On Git, tags are often used in order to tag specific commits that may be more important than others.
Tags may be used in order to bookmark certain events : releases, bug-fixes or just to add an informative and descriptive note to a commit.
On GitHub, tags are often associated with actual product releases for example.
However, in some cases, you may want to delete Git tags easily locally or remotely.
Delete a local Git tag
In order to delete a local Git tag, use the “git tag” command with the “-d” option.
$ git tag -d <tag_name>
For example, if you wanted to delete a local tag named “v1.0” on your commit list, you would run
$ git tag -d v1.0
Deleted tag 'v1.0' (was 808b598)
If you try to delete a Git tag that does not exist, you will simply be notified that the tag does not exist.
$ git tag -d v2.0
error: tag 'v2.0' not found.
If you want to make sure that tags were correctly deleted, simply list your existing tags using the tag command and the “-l” option.
$ git tag -l
<empty>
Delete a remote Git tag
In order to delete a remote Git tag, use the “git push” command with the “–delete” option and specify the tag name.
$ git push --delete origin tagname
Back to the previous example, if you want to delete the remote Git tag named “v1.0”, you would run
$ git push --delete origin v1.0
To https://github.com/SCHKN/repo.git
- [deleted] v1.0
To delete a remote Git tag, you can also use the “git push” command and specify the tag name using the refs syntax.
$ git push origin :refs/tags/<tag>
Back to the example, in order to delete a tag named “v1.0”, you would run
$ git push origin :refs/tags/v1.0
To https://github.com/SCHKN/repo.git
- [deleted] v1.0
Why should we specify the “refs/tags” instead of just specifying the tagname?
In some cases, your tag may have the same name as your branch.
If you tried to delete your Git tag without specifying the “refs/tags” you would get the following error
$ git push origin :v1.0
error: dst refspec v1.0 matches more than one.
error: failed to push some refs to '<repository>'
As a consequence, you need to specify that you are actually trying to delete a Git tag and not a Git repository.
Conclusion
In this tutorial, you learnt how you can easily delete a local and a remote Git tag.
If you are curious about Git, we wrote other tutorials on the subject :
Also if you are interested in software engineering, we have a complete section dedicated to it on the website, have a look!
9 comments
[…] How To Delete Local and Remote Tags on Git […]
Thank you for the guide
Worked very well!!
[…] How To Clear Git Cache APT Package Manager on Linux Explained How To Check RAM on Linux How To Delete Local and Remote Tags on… Home Software Engineering How To Checkout Git Tags Software […]
Very straight-forward. Thank you!
This was very helpful! i thought i was stuck with my tags… but then i found this.
Thank you! Keep up the good work!
When deleting a tag using the refs syntax why don’t you specify delete?
$ git push origin :refs/tags/v1.0
$ git push –delete origin :refs/tags/v1.0
Thank you very much, it helped me a lot!
The instructions here give the false impression that “-d” should be used for local tag operations and “–delete” for remote tag operations. “-d” and “–delete” are equivalent and interchangeable.