What are tags in git?

Git is a free, open-source, distributed version control system that keeps track of the changes made throughout a project's life cycle. Its features to create branches, merges, and tags empower a developing team to work concurrently and efficiently on projects.

Git tags point to specific commits in the repository's commit history. We usually tag commits on releasing a new version or marking a commit as important. Git tags are similar to git branches, but git branches progress and change with each commit, whereas tags are permanent and do not change.

Real-world example

Now that we know what git tags are, let us consider a real-world example to learn more about them.

Let's consider that there is a team of developers working on a web application. The team uses git to manage the source code. After months of rigorous development and testing, they have finally reached the phase to make the first release of the web application. To mark this event, they create a git tag with the name version 1.0.0.

After another month, the team decides to release a major feature of the application and name its tag as version 2.0.0. With the help of these tags, the team can easily navigate to the application's code when the releases where made. The diagram below shows a git tag associated with a commit:

Git tag attatched to a commit
Git tag attatched to a commit

In the coming sections, we will explore different git types and their implementations.

Types of tags

There are two types of tags in Git:

  • Annotated tags

  • Lightweight tags

Annotated tags

These tags store extra information in the tag data, including the tagger's name, email, tag message, and date. We use annotated tags when making a final version release of the project. It allows the developer to write a message in the tag that can be useful in the future.

To create an annotated tag, we use -a or --annotate as shown below:

git tag --anotate <tag-name> -m <message>
Syntax to create annotated tags

<tag-name>: We can give our tag a name in place of <tag-name>.

<message>: We can give our tag a message in place of <message>.

Lightweight tags

These tags only point to a commit and do not store additional information, including the name, email, message, and creation date. They are used when we want to mark a commit but do not want additional information along the tag.

To create a lightweight tag, we simply use the following command:

git tag <tag-name>
Syntax to create lightweight tags

We can give any name to our lightweight tag by replacing it with the <tag-name>.

Push tags

Git provides us commands to push an individual tag by its name or push all tags in a go. The commands are given below:

// Push a specific tag to the remote server
git push origin <tag-name>
// Push all tags
git push origin --tags
//or
git push --tags
Syntax to push tags to the server

List tags

To list all the tags present in the repository, we can run the following command:

git tag
Command to view all tags

We can run the following command to view the details of a specific tag:

git tag show <tag-name>
Command to show details of a specific tag

We can replace <tag-name> with the tag name we want to view the details of.

Step-by-step procedure

Now that we have learned the basics of git tags, we will explore the step-by-step procedure to create them in our repository.

1. Install git

To create tags, we need to install git first. For that, we can run the following command in the terminal.

apt-get install -y git

2. Confirm git installation

Once we install git, we can confirm the installation by running the following command:

git --version

Running the command will display the version of git installed. If not, then git has not been installed correctly.

3. Clone repository

We can clone the repository in which we want to create the tags. Using git, we can accomplish this task. The command to clone a repository is:

git clone <link to repository>

Running the command clones the repository, and the project folder is created.

4. Move to the project directory:

Now, we can navigate to the project folder using the following command:

cd <directory name>

Replace <directory-name> with the cloned project's folder name.

5. Bring changes to the project directory:

Now, we will be creating a change in the project folder. The change can be created by updating any file or adding functionalities to the project.

Note: Just for replicating the scenario where we make changes in our project, we have created a blank hello.txt file using the following command

touch hello.txt

6. Stage changes

We will stage the changes to git using the following command:

git add .

7. Confirm staged changes

Once the changes have been staged, we can confirm it by checking the current state of the folder by using the following command:

git status

8. Configuring git

Configure git by providing our email or user name in the following commands.

git config --global user.email "you@example.com"
git config --global user.name "Your name"

The email and user name provided should be the ones on which our GitHub account is created.

9. Add a commit message

Now we can commit the changes made in the folder by using the following command. In place of <Your message>, we can write any message.

git commit -m "<Your message>"

10. Create a tag

We can now create a tag on the commit using the following command. Any name can be given to the tag by replacing <tag name>:

git tag <tag name>

11. View the created tag:

Now that our tag has been created, we can view the created tags using the following command:

git tag

Live demonstration

Let's do a live demonstration of creating tags on our own repositories. Below, we can see the commands that have been discussed above:

apt-get install -y git # Install git
git --version # Check git version
git clone <link to repository> # Clone your repository
cd <directory name>
touch hello.txt # " OR Make any changes in the folder so that we can make a commit"
git add .
git status
git config --global user.email "youremail@email.com"
git commit -m "<Your message>"
git tag <tag name> # Create a tag on the commit
git tag
Commands to create a tag

In the terminal below, we can run the commands and create git tags.

Note: Replace <link to repository> with you repository link, <directory name> with the project directory, <Your message> with your commit message, and <tag name> with your own tag name.

Terminal 1
Terminal
Loading...

Tag advantages

Some of the advantages of adding tags in the git repository are given below:

  1. They help in marking important milestones throughout the project, for example, version releases.

  2. They help developers, maintainers, and contributors effortlessly navigate through the repository to reach a point in the project's history and work on it.

  3. Unlike branches, tags do not change with time, and they keep on referencing a specific commit.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved