Tagging is another great feature Git provides. A tag acts as a pointer to an specific commit, easing its identification. Usually it's used to mark release points on codebases (e.g. v0.1.0, v1.0, etc).
Do not type the
$ sign you see in the command examples in this article.
That's just an indicator that you should run the command that follows it in your command
Git provides two types of tags: lightweight and annotated. "A lightweight tag is very much like a branch that doesn't change — it's just a pointer to a specific commit." (Chacon 39)
To create a lightweight tag you run:
$ git tag tag-name
After that you can go to an specific tag by running:
$ git checkout tag-name
That's much easier than checking out an specific commit by its hash ID right?
But usually it's recommended that you create annotated tags. Annotated tags contain the tagger's name and email, the date and a message, and they can be signed and verified with GNU Privacy Guard (GPG).
To create an annotated tag you run:
$ git tag -a tag-name -m "tag message"
To list all your tags you run:
$ git tag
And to see more information about any specific (annotated) tag:
$ git show tag-name
By default, the
$ git push command doesn't send tags to remote repositories.
To send them you have to do the same thing as with branches:
$ git push remote-name tag-name
If you have several tags and want to send them all at once:
$ git push remote-name --tags
That's it. Git makes it super easy and fast to tag your codebase. Tagging is a best-practice on not trivial projects, as it makes it very simple to find release points on your codebase. Every time you're going to make a release, deploying code to a server, consider tagging your codebase before doing so.
Chacon, Scott. Pro Git. Apress, 2009.
Tagging with Git by Flavio Silva is licensed under a Creative Commons Attribution 4.0 International License.