Better Git: git fetch not getting tags

I just ran into a little gotcha with regard how fetch handles tags. When it pulls down commits, you will usually see that it also pulls down tags. I was a little confused today when fetch was refusing to pull a tag that was clearly in the repository (“git ls-remote --tags“) lets you see tags available on the remote).

I kept running the fetch command but the tag wouldn’t get pulled down. The reason has to do with the way fetch works, it only fetches tags that are direct references to a commit that is in a branch being fetched. To get all tags regardless of what commits they reference use the fetch in the following way.


# Passing the –tags argument makes fetch retreive tags explicitly.
git fetch –tags

From the git manual (“git help fetch”):

-t, –tags Most of the tags are fetched automatically as branch heads are downloaded, but tags that do not point at objects reachable from the branch heads that are being tracked will not be fetched by this mechanism. This flag lets all tags and their associated objects be downloaded. The default behavior for a remote may be specified with the remote.<name>.tagopt setting. See git-config(1).

This will effectively do the inverse of normal fetch. It will fetch all tags, and bring with is any necessary commits.

Hope this helps some poor confused folks out there a little bit of greif.



Leave a comment