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.
Tags are ref's that point to specific points in Git history. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1. 0.1). A tag is like a branch that doesn't change. Unlike branches, tags, after being created, have no further history of commits.
Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.
A tag is used to label and mark a specific commit in the history.
It is usually used to mark release points (eg. v1.0, etc.).
Although a tag may appear similar to a branch, a tag, however, does not change. It points directly to a specific commit in the history and will not change unless explicitly updated.
You will not be able to checkout the tags if it's not locally in your repository so first, you have to fetch
the tags to your local repository.
First, make sure that the tag exists locally by doing
# --all will fetch all the remotes. # --tags will fetch all tags as well $ git fetch --all --tags --prune
Then check out the tag by running
$ git checkout tags/<tag_name> -b <branch_name>
Instead of origin
use the tags/
prefix.
In this sample you have 2 tags version 1.0 & version 1.1 you can check them out with any of the following:
$ git checkout A ... $ git checkout version 1.0 ... $ git checkout tags/version 1.0 ...
All of the above will do the same since the tag is only a pointer to a given commit.
origin: https://backlog.com/git-tutorial/img/post/stepup/capture_stepup4_1_1.png
# list all tags $ git tag # list all tags with given pattern ex: v- $ git tag --list 'v-*'
There are 2 ways to create a tag:
# lightweight tag $ git tag # annotated tag $ git tag -a
The difference between the 2 is that when creating an annotated tag you can add metadata as you have in a git commit:
name, e-mail, date, comment & signature
$ git tag -d <tag_name> Deleted tag <tag_name> (was 000000)
Note: If you try to delete a non existig Git tag, there will be see the following error:
$ git tag -d <tag_name> error: tag '<tag_name>' not found.
# Delete a tag from the server with push tags $ git push --delete origin <tag name>
In order to grab the content of a given tag, you can use the checkout
command. As explained above tags are like any other commits so we can use checkout
and instead of using the SHA-1 simply replacing it with the tag_name
Option 1:
# Update the local git repo with the latest tags from all remotes $ git fetch --all # checkout the specific tag $ git checkout tags/<tag> -b <branch>
Option 2:
Since git supports shallow clone by adding the --branch
to the clone command we can use the tag name instead of the branch name. Git knows how to "translate" the given SHA-1 to the relevant commit
# Clone a specific tag name using git clone $ git clone <url> --branch=<tag_name>
git clone --branch=
--branch
can also take tags and detaches the HEAD at that commit in the resulting repository.
git push --tags
To push all tags:
# Push all tags $ git push --tags
refs/tags
instead of just specifying the <tagname>
.Why?
refs/tags
since sometimes tags can have the same name as your branches and a simple git push will push the branch instead of the tagTo push annotated tags and current history chain tags use:
git push --follow-tags
This flag --follow-tags
pushes both commits and only tags that are both:
From Git 2.4 you can set it using configuration
$ git config --global push.followTags true
Cheatsheet:
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