I need to understand Git pull origin master --allow-unrelated-histories better
I have a local and a remote repository and the local repository points to the remote repository.
When I created the remote repository, I placed a .gitignore file in it. Then, I created the local repository. It didn't have that file. Instead, the local repository had other files.
I have a question about:
git pull origin master --allow-unrelated-histories
When I ran the above command, the file .gitignore was downloaded into my local repository, but what else the above command does?
These are all the commands I ran from the Windows command prompt (I am on the Windows operating system) while being at the directory of the local repository in order to create the local repository, point it to the remote repository and upload the local files to the remote repository (one of these commands is the command that I need to understand, git pull origin master --allow-unrelated-histories):
git init
git add .
git commit -m "Initial commit"
git remote add origin https://...git
git pull origin master --allow-unrelated-histories
git push origin master
-
I have a local and a remote repository and the local repository points to the remote repository.
More specifically, you have a local tracking branch:
Remote-tracking branch names take the form
<remote>/<branch>
. For instance, if you wanted to see what the master branch on your origin remote looked like as of the last time you communicated with it, you would check theorigin/master
branch.
- When I ran the above command, the file .gitignore was downloaded into my local repository, but what else the above command does?
git pull runs git fetch with the given parameters and then depending on configuration options or command line flags, will call either git rebase or git merge to reconcile diverging branches.
So apparently, ".gitignore" was the only (committed) change between your remote and your local repos at that time.
I suspect "--allow-unrelated-histories" was both unnecessary, and probably irrelevant to understanding what actually happened:
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.
Only useful when merging.
The "official" Git documentation is on-line: Git Reference
Here's book I always keep by my side: Git in Practice, Mike McQuaid.