A nice and simple question - is the function of "git fetch" a strict sub-set of git fetch --tags
?
I.e. if I run git fetch --tags
, is there ever a reason to immediately run git fetch
straight afterward?
What about git pull
and git pull --tags
? Same situation?
Note: this answer is only valid for git v1.8 and older.
Most of this has been said in the other answers and comments, but here's a concise explanation:
git fetch
fetches all branch heads (or all specified by the remote.fetch config option), all commits necessary for them, and all tags which are reachable from these branches. In most cases, all tags are reachable in this way.git fetch --tags
fetches all tags, all commits necessary for them. It will not update branch heads, even if they are reachable from the tags which were fetched.Summary: If you really want to be totally up to date, using only fetch, you must do both.
It's also not "twice as slow" unless you mean in terms of typing on the command-line, in which case aliases solve your problem. There is essentially no overhead in making the two requests, since they are asking for different information.
git fetch upstream --tags
works just fine, it will only get new tags and will not get any other code base.
In most situations, git fetch
should do what you want, which is 'get anything new from the remote repository and put it in your local copy without merging to your local branches'. git fetch --tags
does exactly that, except that it doesn't get anything except new tags.
In that sense, git fetch --tags
is in no way a superset of git fetch
. It is in fact exactly the opposite.
git pull
, of course, is nothing but a wrapper for a git fetch <thisrefspec>; git merge
. It's recommended that you get used to doing manual git fetch
ing and git merge
ing before you make the jump to git pull
simply because it helps you understand what git pull
is doing in the first place.
That being said, the relationship is exactly the same as with git fetch
. git pull
is the superset of git pull --tags
.
The general problem here is that git fetch
will fetch +refs/heads/*:refs/remotes/$remote/*
. If any of these commits have tags, those tags will also be fetched. However if there are tags not reachable by any branch on the remote, they will not be fetched.
The --tags
option switches the refspec to +refs/tags/*:refs/tags/*
. You could ask git fetch
to grab both. I'm pretty sure to just do a git fetch && git fetch -t
you'd use the following command:
git fetch origin "+refs/heads/*:refs/remotes/origin/*" "+refs/tags/*:refs/tags/*"
And if you wanted to make this the default for this repo, you can add a second refspec to the default fetch:
git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*"
This will add a second fetch =
line in the .git/config
for this remote.
I spent a while looking for the way to handle this for a project. This is what I came up with.
git fetch -fup origin "+refs/*:refs/*"
In my case I wanted these features
refs/*:refs/*
+
before the refspec-u
-p
-f
I'm going to answer this myself.
I've determined that there is a difference. "git fetch --tags" might bring in all the tags, but it doesn't bring in any new commits!
Turns out one has to do this to be totally "up to date", i.e. replicated a "git pull" without the merge:
$ git fetch --tags
$ git fetch
This is a shame, because it's twice as slow. If only "git fetch" had an option to do what it normally does and bring in all the tags.
Source: Stackoverflow.com