If your branch has an associated remote tracking branch that means its configuration is like:
git config branch.[branch-name].remote [remote-name]
git config branch.[branch-name].merge [remote-master]
The key part of git fetch
which explain the difference between the two commands is:
<refspec>
The format of a
<refspec>
parameter is an optional plus+
, followed by the source ref<src>
, followed by a colon:
, followed by the destination ref<dst>
.
The remote ref that matches<src>
is fetched, and if<dst>
is not empty string, the local ref that matches it is fast-forwarded using<src>
.
Let me repeat it:
if <dst>
is not empty string, the local ref that matches it is fast-forwarded using <src>
.
Knowing that:
-
git fetch
is equivalent togit fetch origin master:master
(from the default value of your branch config), so it will update the remote tracking branch: the destination of the refspec is specified for you. -
git fetch origin master
is equivalent to “git fetch origin master:
“, not to “git fetch origin master:master
“; it stores fetched value of ‘master
‘ branch (of remote ‘origin
‘) inFETCH_HEAD
, and not in ‘master
‘ branch or remote-tracking ‘remotes/origin/master
‘ branch (from Jakub NarÄ™bski’s answer)
In other words, you didn’t specify the destination of your refspec