Git tags are identifiers for specific commits in a git repository. They can consist of alphabets, number and special characters. Tags make it easy to quickly find the specific commit and understand the development flow better. They are also used to mark important milestones in development, or as a starting point of branch. However, unlike branch, a tag points to one and only one commit, and any downstream commits will not have that tag. Sometimes you may have accidentally created tag at a wrong commit, and may need to delete it. In this article, we will learn how to delete git tags. Git tags are unique to the repository where they are present. Once a tag is deleted it becomes available for re-use.
How to Delete Git Tags
Here is the syntax to delete git tag. You can use the same commands in Linux, Windows & Mac.
$ git tag -d [tag_name]
Here is an example to delete tag reg1.1
$ git tag -d reg1.1
How to Delete Tag from Remote Repository
The above command will only delete the tag from your local repository. If you had pushed your tag to your remote repository, you will need to remove the tag from there also. For this purpose, you will need to run the following command.
$ git push origin --delete origin [tagName]
Here is an example.
$ git push origin --delete origin reg1.1
Alternatively, you can also use the following command to delete the remote tag.
$ git push origin :refs/tags/[tagName]
Here is the example of above command.
$ git push origin :refs/tags/reg1.1
How to List Tags
Once you have deleted the required tags, you can verify that they have deleted by listing all tags in your repository, using the following command.
$ git tag -l
In this short article, we have learnt how to delete git tags. It is important to remember that if you have pushed your tags to the remote repository, then you will need them once you have deleted tags from local repository.
Also read:
How to Drop One or More Columns in Python Pandas
Types of Testing in Python
How to Generate SSH Keys for Git Authorization
How to Download File in Django
How to Check if File Exists in Python
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.