What is the difference between these two commands?
git fetch
and
git fetch origin
What is the difference between these two commands?
git fetch
and
git fetch origin
This is simpler than the linked answer (which is really about what name(s) are updated with git fetch origin
vs git fetch origin master
vs git fetch origin master:master
; and that answer is slightly different for very old versions of Git as its behavior changed a bit in Git version 1.8.4).
To quote the git fetch
documentation:
When no remote is specified, by default the
origin
remote will be used, unless there’s an upstream branch configured for the current branch.
In other words:
git fetch
is exactly the same as:
git fetch origin
unless the current branch has an upstream setting that refers to a remote other than origin
. So if, for instance, the current branch is rumpelsnakeskin
and the upstream of rumpelsnakeskin
is habitat/rumpelsnakeskin
, then git fetch
means git fetch habitat
. But if the current branch is, say, master
and its upstream is origin/master
or is not set at all, then git fetch
means git fetch origin
.
git fetch
fetch the whole all remotes.
but in git fetch origin
by using origin
you specify the remote
which need to be fetched