I have been playing around with git and stuck with concepts of git fetch.
I have tried and observed following scenarios:
1)
$ git fetch
All the remote branches are fetched and all the corresponding remote-tracking branches are updated. I understand that it looks at .git/config file and uses default remote repository location and default fetch refspec which is generally "refs/heads/:refs/remotes/origin/". It does not fast forward any local branches.
2)
$ git fetch origin
Observed same as 1)
3)
$ git fetch origin master
Only master branch is fetched and remote-tracking branch origin/master is updated. Does not fast forward the local 'master' branch.
4)
$ git fetch origin master:master
Only master branch is fetched and remote-tracking branch origin/master is updated. Fast forwards the local 'master' branch.
Understanding 1) and 2) was straightforward. However 3) and 4) confuses me.
What does a fetch command had to do anything with local branches? Why does it fast forward the local branch? (Proof that it affects the local branch is when I try git fetch origin master:master
, while the master branch is checked out, it throws the following error: fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository
)
According to my intuition, on any type of fetch command, updating the remote-tracking branches is default behavior. However when git fetch origin master
is executed, it has an additional behavior of updating FETCH_HEAD. When git fetch origin master:master
is executed, it has an additional behavior of updating local branch 'master'. Is my intuition right?
Does it interpret git fetch origin master:master
as git fetch origin refs/heads/master:refs/heads/master
? (Maybe redundant to my previous question)
Does it interpret git fetch origin master
as git fetch origin refs/heads/master:
?