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.

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.

About these ads

One Comment on “Better Git: git fetch not getting tags”

  1. Excellent goods from you, man. I have understand your stuff previous to and you
    are just too fantastic. I actually like what you have acquired here,
    really like what you are saying and the way in which you say it.

    You make it entertaining and you still take care
    of to keep it smart. I can’t wait to read far more
    from you. This is actually a wonderful web site.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 253 other followers