How to Delete Tags in Git

Azhar Bashir Khan Feb 02, 2024
  1. Using git tag -d to Delete Local Tags in Git
  2. Using git push to Delete Remote Tags in Git
How to Delete Tags in Git

In this tutorial, we will learn how to delete tags in Git.

We use tags in a repository in Git to mark certain occasions like production releases, feature releases, bug fixes, etc. And sometimes, we use tags to add information to some important commits.

On some occasions, we want to delete some tags, which we added earlier but are no longer relevant. We will now illustrate this with an example.

Please note tags can be local or remote in Git.

Using git tag -d to Delete Local Tags in Git

Suppose we have a tag named rel1.0 which we no longer need and want to delete. We can delete it as follows.

$ git tag -d rel1.0
Deleted tag 'rel1.0' (was 103a234)

The git tag command with the -d option is used to delete local tags. If we try to delete a tag not present in the repository, we get the following error.

$ git tag -d rel1
error: tag 'rel1' not found.

We can check for the deletion of the tag by listing all the existing tags in the repository as follows.

$ git tag -l 
<empty>

Using git push to Delete Remote Tags in Git

Suppose we have a remote tag named prod1.0 in the repository. We can delete the remote tag using the git push command with the --delete option.

$ git push --delete origin prod1.0

To https://github.com/myrepos/prod.git
 - [deleted]         prod1.0

Sometimes, we may have a tag with the same name as the branch. In such cases, we need to use the git push command with the refs syntax instead of the --delete option, as follows.

$ git push origin :refs/tags/prod1.0

To https://github.com/myrepos/prod.git
 - [deleted]         prod1.0

Thus, we have elaborated on deleting tags, both local and remote, in a Git repository.

Related Article - Git Tag

Related Article - Git Push