How to delete local and remote git tags (WITH EXAMPLES)

Once you have created a git tag, you might realize that the git tag name is wrong and does not match 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 local git tag simply run the "git tag" command with the -d option and tag name. To know the tag name you can run the "git tag" command with the -l option to list all tags, identify the tag you want to delete.

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

$ 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 the -l option to verify that the tag is deleted.

How to delete remote git tag

There are two ways to delete the remote git tag.

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 remote git tag using the command below.

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

For directly deleting the remote git tag, use the "git push origin" command with --delete option and tag name.

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

Recap

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

 

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

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
3 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.