Creating tags in Git marks particular points in a project's development history, such as a new version release. While renaming a tag works for correcting tag typos, creating a wrong tag requires cleaning up the repository and deleting the unnecessary tag, both locally and remotely.
In this tutorial, you will learn to delete a local and remote Git tag with examples.
- A Git repository.
- Git installed (see how to install Git on Windows, macOS, Ubuntu, CentOS 7, CentOS 8)
Git Delete Local Tag
Local tags are stored only in the local repository, and they are not synced with remote repositories. Make sure to delete unnecessary tags before pushing them to a remote repository.
In the sections below, we show different examples of deleting tags locally.
Delete a Single Tag
The syntax for deleting a tag from the local repository is:
git tag -d [tag_name]
For example, to delete a tag named
git tag -d v1.3
The command deletes the tag and outputs the result. If the command outputs an error, make sure you specified the proper tag name and that the tag exists.
For example, trying to delete a non-existing tag gives the following error:
Delete Multiple Local Tags
It is also possible to delete multiple local tags at once by listing them after the command. For example:
git tag -d v1.5 v1.6 v1.8
The command deletes all the specified tags.
Delete All Local Tags
In case you want to start from scratch and delete all local tags, use the following command:
git tag -l | xargs git tag -d
Note: Learn to use the xargs Linux command to convert standard input into arguments for another command.
See Existing Tags
Ensure that the tags are deleted by listing all existing tags. Run the following command:
git tag -l
The output lists all existing tags and shows that the previously deleted tags no longer exist in the repository.
Git Delete Remote Tag
If you push a wrong tag to a remote repository, it isn't enough to delete it only locally. When a tag remains in a remote repository, the next pull request restores it in the local repository as well.
There are two ways to delete the tag remotely.
Push an Empty Reference to Remote
Use the following syntax to delete a tag remotely by pushing an empty reference to the remote tag name:
git push [remote_name] :[tag_name]
Important: Git has a tag namespace and a branch namespace, allowing a branch and tag to share the same name. If you are using the same name for a branch and a tag, specify the full ref to make sure you delete the tag and not the branch:
git push [remote_name] :refs/tags/[tag_name]
2. Use the Delete Option
Another way to delete a tag is to use the
-d) option. The syntax is:
git push --delete [remote_name] [tag_name]
- Delete a Single Remote Tag
The following example shows how to delete a single remote tag from the origin repository:
git push --delete origin v1.6
- Delete Multiple Remote Tags
This command also allows you to delete multiple tags at once. The syntax is:
git push --delete [remote_name] [tag1] [tag2] ...
git push --delete origin v1.8 v1.0
The command deletes the specified remote tags.
- Delete All Remote Tags
1. To delete all remote tags, first fetch the remote tags by running:
2. Use the following syntax to delete all remote tags:
git push [remote_name] --delete $(git tag -l)
git push origin --delete $(git tag -l)
The command deletes all the tags from the specified remote repository.
This tutorial showed different ways to delete a single or multiple tags from the local and remote repository. If you have only mistyped a tag name, it is also possible to rename a tag.
Next, read our article on more basic Git tag actions.
For more Git tag tutorials, read how to checkout a Git tag or learn to manage Git tag releases.