Running git fetch without any parameters will extract all the links to the remotes and write them to a .git/FETCH_HEAD . Typically, the contents of a file look something like this:
37301df96597ac037f8e7e846fea6fc7df77bea5 branch 'master' of github.com:user/repo 593539e8a98ba5980d4b645db3b0f506bb9b6a2c not-for-merge branch 'branchOne' of github.com:user/repo
When you have such a file in the .git directory, you can use it as a link if the first thing in this file is either a 40-character hexadecimal number or a shorter hexadecimal number, an existing commit.
Knowing this, we see that after running git fetch FETCH_HEAD link will be resolved to what happens on the first line
It seems that the order of the contents of .git/FETCH_HEAD not guaranteed to contain the first link for the current branch.
Having tried it in different repositories, it seems that in the first line there is always the current branch, and thus git fetch; git merge FETCH_HEAD git fetch; git merge FETCH_HEAD works as expected. However, in other repositories, the contents of .git/FETCH_HEAD will be ordered differently, and often the first line will be a link to the remote commit of another branch, which makes the FETCH_HEAD link FETCH_HEAD .
Why this behaves differently is a mystery to me.
As a solution, if git fetch remote_name branch_name , only this particular branch is selected, and only that one line will be displayed in the contents of .git/FETCH_HEAD , making the FETCH_HEAD link always valid.
Lopse
source share