Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching a remote tag

Tags:

git

I have used following command to fetch a remote tag, it completed successfully by fetching the remote objects.

git fetch origin <tag name >

After that gave following command to switch to tag, but it gave error: pathspec error.

git checkout <tag name>

Now I tried following command.

git fetch --tags

After that the command, git checkout <tag name> executed successfully.

Can you help to understand during git fetch origin <tag name> why the tag was not fetched.

like image 843
Ravi A Avatar asked Oct 25 '25 12:10

Ravi A


1 Answers

The git fetch documentation does mention:

By default, tags that point at objects that are downloaded from the remote repository are fetched and stored locally

However: if you are fetching a refspec referencing a tag name directly, you are actually fetching what the tag points to, but: you don't specify the refspec destination.
So you see only:

 * tag aTag -> FETCH_HEAD

The tag reference is copied to .git/FETCH_HEAD, but not created locally.

As opposed to git fetch --tags, which is the equivalent of using the refspec refs/tags/*:refs/tags/*: source (the tags/*) and destination (in your repo: tags/*) are specified, the remote tags are created locally.

See more at "A git tag doesn't seem to be available after explicitly fetching the tag"

A git fetch origin refs/tags/<tag name>:refs/tags/<tag name> would have worked.
The git checkout <tag name> would not have yield "error: pathspec '<tag name>' did not match any file(s) known to git"

like image 100
VonC Avatar answered Oct 27 '25 01:10

VonC