Tagging In Git

Tagging allows us to mark a specific point in the commit history (snapshot). A tag is typically used to mark a project release.

Tags in Git can be of two types:

  1. Lightweight Tag
  2. Annotated Tag

A lightweight tag is just a pointer to a specific point in the commit history. It is basically used to tag a point temporarily. It does not store any information other than the commit point information.

Annotated tags are object that are stored in the Git database. It contains information like the name, email, date, tag message etc. about the tag. It is generally recommended to use annotated tags so that all these information can be stored.


Creating a Tag

Git provides the ‘git tag’ command to work with tags.

git tag

To create an annotated tag we can use the following command:

git tag -a <tag_name> -m <tag_message>

To create a lightweight tag we need not provide any options since it doesn't store any information. We can use the below command to create a lightweight tag.

git tag <tag_name>

The image below shows how to create annotated tag. Note that we have used the 'git show' command to view a tag. Since it's an annotated tag it shows the tagger information, the date when the tag was created and the tag message along with the commit information at the tag location.

git-tag

The image below shows how to create a lightweight tag. Also notice that the 'git show' command only shows the commit information at the tag location since it a lightweight tag.

git-tag-lightweight

We can use the 'git tag' command alone to list the available tags. Its usage can be noticed in the example images above.

All the tag we created were on the latest commit snapshot. We can also create a tag on the previous commit snapshots. We can use the commit checksum to do so as shown below:

git tag -a 946d1197c5717f4eecd26c921feccdeba91ed25c -m 'New Tag Location'
git tag -a 946d119 -m 'new_tag'                   // A part of the checksum is also enough

Pushing Tags to Remote Repository

Tags are not send to the remote repository by the git push command. We need to explicitly send these tags to the remote server by using the following command:

git push origin <tagname>

Example:

git push origin v1.0

We can push all the tags at once by using the below command:

git push origin --tags

RELATED ARTICLES

Git Branching Support

Branching is a major part of any modern version control system. Git provides a unique branching feature which sets it apart from other version control systems. This article covers the various aspec...

View Article

Git Overview

GIT is an open source distributed version control system that emphasizes on speed and efficiency. This article covers some of the basics of the GIT VCS and also discuss about the GIT config tool.

View Article

Creating and using GIT Repository

A GIT repository is where GIT stores all the project files. We can either create a new repository or clone an existing one. This article shows how to create/clone a repository and few basic operatio..

View Article