What is git tag, How to create tags & How to checkout git remote tag(s)

Viewed 848507

when I checkout remote git tag use command like this:

git checkout -b local_branch_name origin/remote_tag_name

I got error like this:

error: pathspec origin/remote_tag_name did not match any file(s) known to git.

I can find remote_tag_name when I use git tag command.

6 Answers

In order to checkout a git tag , you would execute the following command

git checkout tags/tag-name -b branch-name

eg as mentioned below.

 git checkout tags/v1.0 -b v1.0-branch

To find the remote tags:

git ls-remote --tags origin

Create a tag with the given tag message

git tag <tag_name> -a -m "tag message"

To Push a single tag to remote

git push origin <tag_name>

Push all tags to remote

git push origin --tags

When I want the code at a tag, I may not want to create a branch (typically, I only need a full branch if I'll be hotfixing it).

To temporarily rewind your branch to the code at the tag, do this:

git reset --hard tags/1.2.3

I can use it briefly as needed, then get back to HEAD of the branch when I'm done, with a simple git pull.

To get the specific tag code try to create a new branch add get the tag code in it. I have done it by command : $git checkout -b newBranchName tagName

This is bit out of context but in case you are here because you want to tag a specific commit like i do

Here's a command to do that :-

Example:

git tag -a v1.0 7cceb02 -m "Your message here"

Where 7cceb02 is the beginning part of the commit id.

You can then push the tag using git push origin v1.0.

You can do git log to show all the commit id's in your current branch.

Related