1. Home
  2. Git
  3. Git Tutorial
  4. Git – Tagging

Tagging in Git

Git also allows users to tag specific version of the repository with meaningful names. For example, you have completed the first version of your application and you want to tag this point.

In this tutorial, you’ll learn how to create tags in a git repository, list existing tags etc.

Create New Tags

Your project has reached to release 1.0. You can tag this point using switch -a with name v1.0 in your repository.

git tag -a "v1.0" -m "Release 1.0"

Push your tag to remote repository using the command:

git push origin tag v1.0 

Counting objects: 1, done.
Writing objects: 100% (1/1), 166 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/tecrahul/firstrepo.git
 * [new tag]         v1.0 -> v1.0

After few days, your project reaches to release 1.2. You tagged this point with name v1.2 and push the tag to the remote.

git tag -a "v1.2" -m "Release 1.2"
git push origin tag v1.2

Now, suppose you forgot to tag your project for version v1.1. You can make a tag to the previous commit later. First, find the commit logs and select the commit to which you need to tag.

git log --pretty=oneline

6adad4e18cac7aab0b681bc0d36ba5a5d8e22408 Updated index.html
d547a760defa66b4728045bc7963a809ab0acd9e Updated index.html
5c2fbc6804b2c849dc47fcf9814c7d40d6db31ac Updated readme
5528ee5296130371aa988f2b660d9b27a2363149 Initial commit


git tag -a "v1.1" -m "Release 1.1" d547a760defa66b4728045bc7963a809ab0acd9e
git push origin tag v1.1

Listing Tags

You can list all the tags available in your repository.

git tag -l

v1.0
v1.1
v1.2

You can see the tag data along with the commit that was tagged by using the git show command:

git show v1.2

tag v1.2
Tagger: Rahul Kumar 
Date:   Sat Feb 24 03:43:01 2018 +0000

Release 1.2

commit 6adad4e18cac7aab0b681bc0d36ba5a5d8e22408
Author: Rahul Kumar 
Date:   Sat Feb 24 03:42:31 2018 +0000

    Updated index.html

diff --git a/index.html b/index.html
index 44e3e53..1a89684 100644
--- a/index.html
+++ b/index.html
@@ -1 +1,2 @@
 Hello, Hi
+Welcome to tecadmin.net

Checkout Tags

You need the code of specific tag for review of fixing some issue. The best way to do this checks out the code for the specific tag to a new branch. The below command will create a new branch named version1.1 using the code from tag v1.1.

git checkout -b version1.1 v1.1

Delete Tags

Assume you have no more need of some old tags. You can delete them using git tag command. For example to remove tag named “v1.0”.

git tag -d v1.0

Deleted tag 'v1.0' (was 1854a1c)

git push origin :v1.0

 - [deleted]         v1.0
Was this article helpful to you? Yes 1 No
Welcome to tecadmin tutorials website