Tags in Git are used to label specific commits (to mark releases, for example).
In this note i will show how to create a Git tag and push it remote repository using the
git tag and
git push commands.
I will also show how to find out the most recent tag name and how many commits ago it has been created.
Cool Tip: How to list all tags in Git! Read more →
Git Create Tag
Create a “lightweight” tag on a current branch:
$ git tag <tag_name>
If you want to include a description with your tag, add
-a to create an “annotated” tag:
$ git tag <tag_name> -a
Create an “annotated” tag with the given message (instead of prompting):
$ git tag <tag_name> -a -m "Message"
Annotated vs Lightweight: A Git tag created with
-a option is called “annotated” tag. Whereas a tag without tagging message is called “lightweight” tag. “Annotated” tags are meant for releases while “lightweight” tags are meant for private or temporary object labels. For this reason, some git commands for naming objects (like
git describe) will ignore “lightweight” tags by default.
At any time you can check if the current commit is tagged or what is the most recent tag name and how many commits ago it has been created:
$ git describe v1.0.1 |--------------- the current commit is tagged with this tag name $ git describe v1.0.3-7-g89fbf84 | | |----- commit hash | |----------- number of commits since the last tag |--------------- the most recent tag name
By default, the
git describe command ignores “lightweight” tags.
If you want to consider all tags, run:
$ git describe --tags
Git Push Tag
Push Tag to Remote: The
git tag command creates a local tag with the current state of the branch. When pushing to a remote repository, tags are NOT included by default. It is required to explicitly define that the tags should be pushed to remote.
Push all tags to remote:
$ git push origin --tags
Push a single tag to remote:
$ git push origin <tag_name>
Cool Tip: How to delete local & remote Git tags! Read more →