What does git fetch followed by checkout FETCH_HEAD do?

What does the following command do:

git fetch <remote> <branch> && git checkout FETCH_HEAD

I have only one local branch (master) and I execute the above command. What changes to my local repository should I expect and how can I verify (see) them?

Enquirer: Roman

||

Solution #1:

You are probably aware of what the first part of your command will do. git fetch <remote> <some_branch> will update the local tracking branch of the branch you specify. But this will not alter the actual local corresponding some_branch on your machine.

When you do a git fetch, Git has a special ref called FETCH_HEAD which points to the branch which was just fetched. In this case, it would point to remote/some_branch, since this is the branch which was just fetched. By doing

git checkout FETCH_HEAD

you would be checking out origin/some_branch in a detached HEAD state. This may or not may not be what you intend, but in any case, your compound command would not actually update the local some_branch. To do that, you would need an additional git merge step, or to just do a git pull from some_branch.

Respondent: Tim Biegeleisen

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.