How to delete git tag from local and remote (With Examples)

Once you have created a git tag, you might realize that the git tag name is wrong and not matching the release pattern. In this scenario, you might want to delete the git tag.

It might be possible you have already pushed the wrong git tag to the remote. So in this tutorial, we will see how to delete a git tag from local as well as from remote.

How to delete local git tag

To delete a git tag simply run "git tag" command with -d option and tag name. To know the tag name you can run "git tag" command with -l option to list all tags, identify the tag you want to delete.

Here is a example of how to delete git tag from local.

$ git tag -l
v1.0
v2.0
v2.5
v3.0
$ git tag -d v2.5
Deleted tag 'v2.5' (was aea93f1727)
$ git tag -l
v1.0
v2.0
v3.0

You can run the "git tag" with -l option to verify that tag is deleted.

How to delete git tag from remote

There are two ways to delete a git tag from a remote.

One is to delete the tag from local first (as shown above) and then push it to the remote. Another option is to delete the tag from the remote. Let check both methods of deleting a tag from remote.

Once the tag is removed from local, the next step would be to remove the tag from the remote as well and this can be done using the command below.

$ git push origin :refs/tags/v2.5
To [email protected]:gulabbisht/drupixels.git
 - [deleted]               v2.5

For directly deleting git tag from remote is to use "git push origin" command with --delete option and tag name.

$ git push origin --delete v2.5
To [email protected]:gulabbisht/drupixels.git
 - [deleted]               v2.5

Recap

So in this blog post, we learned about how to delete git a tag from local and then push that deletion to the remote. And another option to directly deleting the git tag from remote.

 

You can read further about git tags in the following articles:

Tags