How to Delete Tags in Git
In Git, tags are commonly used to mark significant events like releases, bug fixes, or provide additional information about a commit. However, there are situations where you may need to delete them, either locally or remotely.
Maybe you misspelled the correct name of the tag, or you are cleaning up your repository and noticed some old tags lingering around. Deleting tags is a good practice to reduce clutter and keep your repository tidy. Just like branches, tags — especially annotated tags saved as full objects — consume disk space.
Deleting a tag is quite straightforward, whether in your local project or on your remote repository. Let's find out how you can quickly and easily delete tags in Git!
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Deleting a Local Tag in Git
To delete a Git tag in your local project, you can use the git tag -d
command (the -d
option is an alias for --delete
).
$ git tag -d tag-name
You can use this command to delete multiple local tags by specifying multiple tag names:
$ git tag -d tag-name1 tag-name2 tag-name3
To verify that the tag has been successfully deleted, you can type the git tag -l
command (or git tag --list
) to display a list of your current tags.
$ git tag -l
Deleting a Remote Tag in Git
To delete a remote tag, use the git push
command with the --delete
option, as shown in the example below:
$ git push --delete origin tag-name
Just as for local tags, you can also use this command to delete multiple remote tags at once:
$ git push --delete origin tag-name1 tag-name2 tag-name3
If the name of your tag is the same as a branch and you attempt to delete it, you will run into an error:
$ error: dst refspec tag-name matches more than one.
$ error: failed to push some refs to 'https://remote_repository_url'
This error occurs when the tag-name reference matches another reference in the remote repository, meaning there are multiple references (such as branches or tags) with the same name as the one you specified in the remote repository.
To address this issue, you should specify the tag name using the 'refs' syntax. Git uses refs/tags/
as a prefix to reference tags.
This is how the command would look like:
$ git push origin --delete refs/tags/<tag_name>
Alternatively, you could also use this command instead:
$ git push origin :refs/tags/tag-name
Tip
Deleting Tags in Tower
In case you are using the Tower Git client, you can easily delete a tag by right-clicking on it and selecting the appropriate option from the context menu.
Learn More
- More frequently asked questions about Git & version control