Contents...
Git allow you to tag a specific version of the repository. You can easily create git tag in git, git has the similar meaning in Git or GitHub. Git tag also help to identifying the different commit that are enough to be recognised or notice. For example, if you tag a commit with version like 2.0 it means that commit is the final commit before the launching 2.0 version of the repository or software.
In this article we will learn to create git tag in git. If want to learn more about git you can follow my Git Tutorial.
Create git tag in Git
Here we are creating a tag of project which has release to release 2.0. We can use -a options to tag this point with name v2.0 in repository.
$ git tag -a "v2.0" -m "Release 2.0"
Now let’s push this tag to remote repository using below command.
$ git push origin tag v2.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/santosh.prasad/myrepo.git * [new tag] v2.0 -> v2.0
After some time, we want to release 2.2, now we can tag this point with name v2.2 and push the tag to remote repository.
$ git tag -a "v2.2" -m "Release w.2" $ git push origin tag v2.2
Here you noticed that we did not took 2.1 tag because if we forgot to tag 2.1 then we can make a tag to the previous commit later. Doing this first of all you have to check the commit logs and select the commit which you want to tag.
$ git log --pretty=oneline 6adad4e18cac7aab0b681bc0d36ba5a5d8e22408 Updated index.html d547a760defa66b4728045bc7963a809ab0acd9e Updated index.html 5c2fbc6804b2c849dc47fcf9814c7d40d6db31ac Updated readme 5528ee5296130371aa988f2b660d9b27a2363149 Initial commit
We checked the commit log and now we are going to tag with this commit “d547a760defa66b4728045bc7963a809ab0acd9e”
$ git tag -a "v2.1" -m "Release 2.1" d547a760defa66b4728045bc7963a809ab0acd9e
Now push the change to remote repository.
$ git push origin tag v1.1
List all Tags
We can also check and list the all tags which is available in git repository.
$ git tag -l v2.0 v2.1 v2.2
Let’s check the tag data along with the commit details that was tagged.
$ git show v2.2 tag v2.2 Tagger: Santosh Prasad Date: Wed OCT 20 03:43:01 2021 +0000 Release 2.2 commit 6adad4e18cac7aab0b681bc0d36ba5a5d8e22408 Author: Santosh Prasad Date: Wed OCT 20 03:43:01 2021 +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 looklinux.com
Tags Checkout
So here we can have code with specific tag to review and rollback if required in future. So the best way of doing this first check out the code with the specific tag to a new branch. Here using this command we are going to create a new branch named verrsion2.2 using the code from tag v2.2.
$ git checkout -b version1.1 v1.1
Delete Tag
Suppose, If you don’t want some old tags so you can delete them using git tag command. For example, I am going to delete the tag named v2.0.
$ git tag -d v2.0 Deleted tag 'v2.0' (was 1854a1c) git push origin :v2.0 - [deleted] v2.0 Doc navigation
That’s all
FAQs
Can we tag a branch in Git?
In simple world, No, because tags can only be a reference to commit so we can not gat branch in Git.
What is tag in Git?
Git allow you to tag a specific version of the repository. You can easily create git tag in git, git has the similar meaning in Git or GitHub. Git also help to identifying the different commit that are enough to be recognised or notice. For example, if you tag a commit with version like 2.0 it means that commit is the final commit before the launching 2.0 version of the repository or software.
How can I list all tags in Git?
You can list the all tags in git using “git tag -l” command to list the tags in repository.
How can I remote tag in Git?
You can remote tag in git “git tag” command with -d options. For example: git tag -d v2.0. Here deleting v2.0 tag.
How can I clone specific tag in Git?
To clone specific tag in Git use “git clone -b {tagname} {repository} ” command.
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment