Fetch a single tag from remote repository

Viewed 33292

This command fetches all tags:

git fetch origin --tags

This command fetches a specific tag:

git fetch origin refs/tags/1.0.0

But that doesn't let me do:

git checkout tags/2.3.18

How can I fetch a single tag and then perform a checkout?

3 Answers

I read all the answers, but there is not yet mentioned one syntactic sugar. If you need to fetch only one tag as a tag (to checkout later) you can write, for instance for refs/tags/2.3.18:

git fetch origin tag 2.3.18 --no-tags

This is shortcut for already mentioned:

git fetch origin refs/tags/2.3.18:refs/tags/2.3.18 --no-tags

Of course, you may not use --no-tags if you need other tags (according to the default behavior) or if you already explicitly set --no-tag in the clone command or in tagOpt config option(man git-clone).

git fetch origin tag 2.3.18
Related