I am having a hard time understanding the nuances of git-fetch. I understand that doing a fetch
, fetches the remote refs into a local tracking branch.
I
Note that the main maintainer for Git has now (Git 2.1, August 2014) added this explanation for git fetch:
(See commit fcb14b0 by Junio C Hamano (gitster):
You often interact with the same remote repository by regularly and repeatedly fetching from it. In order to keep track of the progress of such a remote repository,
git fetch
allows you to configureremote.
configuration variables..fetch Typically such a variable may look like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
This configuration is used in two ways:
When
git fetch
is run without specifying what branches and/or tags to fetch on the command line, e.g.git fetch origin
orgit fetch
,remote.
values are used as the refspecs---they specify which refs to fetch and which local refs to update..fetch
The example above will fetch all branches that exist in theorigin
(i.e. any ref that matches the left-hand side of the value,refs/heads/*
) and update the corresponding remote-tracking branches in therefs/remotes/origin/*
hierarchy.When
git fetch
is run with explicit branches and/or tags to fetch on the command line, e.g.git fetch origin master
, thes given on the command line determine what are to be fetched (e.g.
master
in the example, which is a short-hand formaster:
, which in turn means "fetch the 'master
' branch but I do not explicitly say what remote-tracking branch to update with it from the command line"), and the example command will fetch only the 'master
' branch.
Theremote.
values determine which remote-tracking branch, if any, is updated..fetch
When used in this way, theremote.
values do not have any effect in deciding what gets fetched (i.e. the values are not used as refspecs when the command-line lists refspecs); they are only used to decide where the refs that are fetched are stored by acting as a mapping..fetch