Cyberithub

How to Tag a Git Commit Using 6 Simple Steps

Advertisements

In this article, we will see how to tag a Git commit Using 6 Simple Steps. If you are using Git based version control system then you might be aware that tagging a commit is like marking or labelling your work as you progress in your project release and deployment activities so that in future if you want to refer then it will be easy for you to identify and access those works. A tag also act as a break point from where you can start a new development or you may even perform a bugfix or hotfix on top of that previous tagged commit if in case any issues got identified.

So as you can visualize there are a number of benefits in tagging a git commit. Hence it is important to understand the right process that you can follow to tag a commit both on local as well as on remote. Here we will see the steps in detail with the help of a real world example.

 

How to Tag a Git Commit Using 6 Simple Steps

How to Tag a Git Commit Using 6 Simple Steps

Also Read: Solved "git add shows unable to index file Permission denied" error

Step 1: Prerequisites

a) You should have a running Windows/Linux/Unix System.

b) You should have git utility installed in your System.

c) You should have access to tag a Specific commit in Remote.

 

Step 2: Clone Your Repo

First of all, you need to clone your repo to the local system by using git clone <repo_url>. In our case, we are having a GitHub repo called atlantis-example which we are cloning into our local system using git clone https://github.com/cyberithub/atlantis-example.git command as shown below. This will create a directory called atlantis-example and copy all the repo files in it.

cyberithub@ubuntu:~$ git clone https://github.com/cyberithub/atlantis-example.git
Cloning into 'atlantis-example'...
remote: Enumerating objects: 32, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 32 (delta 2), reused 8 (delta 1), pack-reused 23
Unpacking objects: 100% (32/32), 5.61 KiB | 168.00 KiB/s, done.

 

Step 3: Switch to Directory

Then you need to switch to the cloned directory by using cd atlantis-example/ command. You can also quickly verify your current branch by using git branch command. For you, it could be a different branch but in our case, we are going to tag a release version to the commit done in master branch.

cyberithub@ubuntu:~$ cd atlantis-example/
cyberithub@ubuntu:~/atlantis-example$ git branch
* master

 

Step 4: Check Your Commit

You need to check the output of git log to identify the commit which you want to tag. In our case, we are going to tag commit ID d09611850909e47b2ee27f4fab23f7ddddd298ab as highlighted below.

cyberithub@ubuntu:~/atlantis-example$ git log
commit 835146f16381163e992e8460d7f61f43a6fa9eae (HEAD -> master, origin/master, origin/HEAD)
Author: CyberITHub <admin@cyberithub.com>
Date: Tue May 23 21:14:07 2023 +0530

Minor changes

commit d09611850909e47b2ee27f4fab23f7ddddd298ab
Author: CyberITHub User <user@cyberithub.com>
Date: Thu Jan 19 14:52:42 2023 +0530

Added Changes

commit 4f32267e28fa4463b08748a50dad2136a39a6992
Author: CyberITHub User <user@cyberithub.com>
Date: Thu Jan 19 13:11:07 2023 +0530

Deleted file

 

Step 5: Tag a Git Commit in Local Repo 

Now to tag version v1.4 to commit ID d096118, you need to use git tag -a v1.4 d096118 -m "Tagging Commit ID: d096118" command as shown below.

cyberithub@ubuntu:~/atlantis-example$ git tag -a v1.4 d096118 -m "Tagging Commit ID: d096118"

After tagging the commit, you can verify it by checking git log output as shown below.

cyberithub@ubuntu:~/atlantis-example$ git log
commit 835146f16381163e992e8460d7f61f43a6fa9eae (HEAD -> master, origin/master, origin/HEAD)
Author: CyberITHub <admin@cyberithub.com>
Date: Tue May 23 21:14:07 2023 +0530

Minor changes

commit d09611850909e47b2ee27f4fab23f7ddddd298ab (tag: v1.4)
Author: CyberITHub User <user@cyberithub.com>
Date: Thu Jan 19 14:52:42 2023 +0530

Added Changes

commit 4f32267e28fa4463b08748a50dad2136a39a6992
Author: CyberITHub User <user@cyberithub.com>
Date: Thu Jan 19 13:11:07 2023 +0530

Deleted file

 

Step 6: Push the Changes to Remote Repo

Finally, you need to push the tag changes done in local to the remote on origin by using git push origin --tags command as shown below.

cyberithub@ubuntu:~/atlantis-example$ git push origin --tags
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 167 bytes | 23.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git+ssh://github.com/cyberithub/atlantis-example.git
* [new tag] v1.4 -> v1.4

Leave a Comment