Git Tag (Tagging) Tutorial

Like most source version control systems, the git provides the tags or tagging mechanism in order to set tags for specific versions. Tags are used to set simple and short names for versions like “development”, “v1”, “v1beta” etc. In this tutorial we examine how to work with tags like listing, setting, searching, and removing tags in Git.

List Tags

Currently, existing tags can be listed with the git tag command easily.

$ git tag
v2.0
v3.0

Alternatively, we can list specific tags by using the -l or --list option. Also, the tag list or search term can be provided to this option.

$ git tag -l "v4.*"
v4.0
v4.1
v4.2

Create/Set Tag

There are two types of tags named lghtweight tag and annotated tag .

Annotated Tag

Annotated tags are complex and when used they are stored as full objects in the Git database. The tag checksummed, tagger name, tagger email, tagging date, the tagging message information is stored too. Annotated tags provide detailed information and when creating or setting annotated tags the -a option is used to set tag and -m option is used to set messages.

In the following example, we add the tag named v1.8 with the message my version v1.8 .

$ git tag -a v1.8 -m "my version v1.8"

Show Tag In Detail

Annotated tag provides detailed information about the tag. This tagging information can be displayed with the git show command. The tag should be provided as a parameter.

$ git show v1.8
tag v1.8
Tagger: İsmail Baydan <[email protected]>
Date:   Sat May 5 20:17:12 2019 -0700

my version 1.8

commit ca82a6dff812311e23d43a007202690a93
Author: Ahmet Ali <[email protected]>
Date:   Mon Mar 11 22:22:16 2018 -0700

    Change version number

We can see that detailed information about the tag “v1.8” is displayed. The Tagger line provides the developer who created this tag. The Date line provides the date and time information about the tag creation. The “my version 1.8” is the tag message provided by the tagger.

Lightweigth Tags

A lightweight tag is just a simple pointer to the specific commit. As a simple tag, just the tag information is provided to the git tag command without any option like -a , -s and -m .

$ git tag v1.8

Also, the lightweight tags related commit can be displayed with the git show command. Just the tag is provided to this command.

$ git show v1.8
commit ca82a6dff812311e23d43a007202690a93
Author: Ahmet Ali <[email protected]>
Date:   Mon Mar 11 22:22:16 2018 -0700

    Change version number

As we can see there are no tag details like the annotated tags. Just the commit information is displayed which is pointed by the specified tag.

Tag Previous Commits or Versions

By default the git tag command is used to tag the current branch’s active commit. But we can also tag previous or historical commits with the git tag . The git tag command is used with the -a option tag information and the commit checksum as the latest parameter.

$ git tag -a v1.8 8fa341be

Delete/Remove Tag

Tags can be removed or deleted using the git tag command with the -d option. Also, the tag name we want to delete is provided as a parameter.

$ git tag -d v1.8

Checkout Using Tags

Generally, the commit checksums are used to check out specific commits. But the tags can be also used to checkout specific commits easily. The git checkout command is used with the tag name we want to checkout.

$ git checkout v1.8

Leave a Comment