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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With