Patricia Sauer - Authentic Programming

Git Tagging

A tag

Tagging means creating a named commit. It gives you the possibility to jump to that commit by using its name instead of its hash value, e.g. you could create a tag for a release version of your software. Let’s say you created your release and want to create a tag for this revision, now.

You can do this by using the tag command:

git tag -a v1.4 -m "version 1.4"

The flag -a lets you create an annotated tag and the flag -m lets you add a tagging message. Annotated tags contain a creation date, the name and e-mail of the tagger, and a tagging message. In case that you used the -s flag in the tag command, a GPG signature will be contained, too.

Annotated tags are the form of tagging which is generally used. Lightweight tags are used for private or temporary labels.

Use the show command to see the information provided for the tag v1.4:

git show v1.4

Lightweight tags

In Git, you can use lightweight tags, too. Lightweight tags do not contain the additional tag information as annotated tags do, i.e. no creation date, no information about the tagger and no tagging message. To create a lightweight tag, simply use the tag command without the flags -a, -m, or -s:

git tag v1.5

You can now use the git show command to see the information provided for the tag v1.5:

git show v1.5

Tagging later on

You can also create a tag after moving forward with your code, i.e. after you added content which should not be contained in the tag. To do so you can create a tag for a specific revision by using the hash of that revision:

git tag -a v1.2 -m “version 1.2” 9fceb02

Pushing tags to origin

To push a specific tag, use the push command and specify the tag to be pushed:

git push origin v1.2

To push several tags, use the push command with the –tags option:

git push origin --tags

Checking out a tag

You may want to check out a tag later on. You can do so by using the checkout command and specifying the name of the tag:

git checkout v1.2


For full reference see Git tag documentation.

Liked this article?

Buy Me A Coffee

© 2018 - 2023 Patricia Sauer