Open In App

How to Create a Tag in a GitHub Repository?

Last Updated : 03 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Tags are one of the important parts of Git and GitHub. We can see in the case of open source projects that the release of a particular version is attached with a tag. Tags are used to memorize a specific moment in history. Even after making multiple changes to the code, we can get back to the particular state of code if it is tagged.

We can create a tag in github repository with the below approaches:

Creating a Tag in GitHub Repository

Step-1: Go to the GitHub repository in which you want to make changes

Screenshot-(1886)
GitHub Repository

Step-2: Go to the Releases section and click on "Create a new release"

Screenshot-(1887)
Create A New Release

Step-3: Click on the dropdown in "Choose a tag" and add the desired tag

Screenshot-(1888)
Choose a tag

Step-4: Choose the branch whose code will be taken for adding a tag

Screenshot-(1890)

Step-5: Give "Release title" of your choice and add any description if you want

Screenshot-(1892)

Step-6: Click on the "Publish release" button present at the bottom to publish that tag

Screenshot-(1893)

Step-7: Now on the project's repository page, we can see that tag under the "Tags" section

Screenshot-(1894)
How to Create a Tag in a GitHub Repository?

Creating tag with Git

We can also create tags on our GitHub repository using git commands. Now for that we will clone the repository then add tags to that and push that tag to the actual GitHub repository. So we will take the following steps to add tag to our repository-

Step-1: Clone that repository

For that, we will go to the code section and copy the repository URL

Screenshot-(1898)

After that, we will use following command to clone the repository

git clone {Link of Repository}
Screenshot-(1899)

Step-2: Use following command to get into the cloned repository

cd {cloned repository name}
Screenshot-(1900)

Step-3: Use the following command to get details of all the previous commits of that repository

git log
Screenshot-(1903)

Step-4: Choose the commit on which we want to apply tag. After choosing, copy the Hash of that commit.

Screenshot-(1904)

Step-5: After that use following command to add the tag

git tag -a {name of tag} {Hash of commit}
Screenshot-(1905)

Step-6: Now we will get Vim Editor to write a tag message. So after writing tag message we will press ctrl+c and write the following to save that message-

:wq
Screenshot-(1906)

Step-7: After that push the tag to the original GitHub repository by following command

 git push origin {name of tag}
Screenshot-(1907)

Step-8: Now we can see that tag in the "Tags" section of that GitHub repository

Screenshot-(1908)
How to Create a Tag in a GitHub Repository?

Benefits of using Tags

  • It is used to mark any release version
  • It helps to go to any previously made commit
  • It helps to mark specific changes in the project
  • It helps to provide documentation for changes
  • It helps to do automation in CI/CD

Next Article
Article Tags :

Similar Reads