bosnadev

№ 21 · 2016-08-20 · 1 min · git

Quick tip: How to delete a tag from a Git repository?

Deleting a wrongly placed Git tag, first from the local repository with git tag -d and then from the remote, such as GitHub, with git push.

written before the past year · entry 21 of 31 · 10 in the past year

This article is out of date
Written in 2016. Versions, APIs and advice may have changed since.

The ability to tag specific changes in commit history has become very important. Programmers use git tag to mark the releases (aka versions) of their applications. That way they can specify a desired version in their dependency tools.

Sometimes we make a mistake; we are all humans after all. We tag a wrong change set, or we tag a version on a wrong branch, or we even tag a version of other component in a current working directory. It happened to me, and I’m confident that some of those things happened to you to.

I’m sure most of you are very familiar with Git and tagging, but if you are not you should check the Git documentation page. If you are just looking for the way to delete the wrongly marked tag, then here’s the quick tip for you; so you don’t have to search through extensive documentation page.

Removing a Tag on the local repository

Deleting a tag on the local Git repository is pretty straightforward:

terminal1 line
$ git tag -d 1.15

You can easily remember it because it’s so declarative. We can read this command as: use git tag command to delete -d tag with a name 1.15 __.

That will delete only the tag on your local repository. If you have already pushed your tag to the remote repository (to the Github for example), then you should also remove a tag on the remote repository.

Removing a tag on the remote repository

To delete a tag on the remote repository, we just need to push information about deleted tag to the remote:

terminal1 line
$ git push origin :refs/tags/1.15

or just:

terminal1 line
$ git push origin :1.15

And that’s it.