Blog

Programming

Posted on — Last updated on November 3, 2021

How to delete a Git tag (locally and remotely)

Just in case I forget how to remove Git tags from a repo, I’m posting a short tutorial here for future reference.

In software development, Git tags represent a version of our code at a given moment in time. Unlike branches, tags are not mutable so people generally use them to mark important points in Git history, like release points (eg. v1.0.0 and so on).

At the same time, because Git tags are immutable and always point to the same commit you can’t change them, what if:

  • There was a change that had to be shipped with this release and you forgot all about it.
  • There’s some debugging code that wasn’t supposed to be included with this release.
  • There’s a really obvious typo that everyone will notice right away.
  • etcetera.

The history of software development is filled with oh-noes-I’m-an-idiot-for-not-paying-attention moments. We all have been there.

You could change whatever needs changing and then just tag a new version – but if that’s not an option (or if you feel like you won’t be able to live with the guilt) you can delete the tag, commit your changes and recreate the tag once more. Here’s how.

Removing a Git tag from a local repository

To delete a tag from your local repo, use the tag command followed by the -d (or –delete) option and the tag version/number:

git tag -d your-tag-name-here

Say for example that you wanted to delete a Git tag named 3.3.1 from your local repository. All you have to do is run this command:

git tag -d 3.3.1

If everything went OK you should see something like this on screen:

Deleted tag '3.3.1' (was 56469e1)

Removing a Git tag from a remote repository

If you have already pushed the tag to a remote repository (eg. GitHub) then you’ll also need to update the remote references right after deleting the tag from your local repository.

Following the same example from before, after deleting the local tag you’ll need to run this command to remove the tag from the remote repository as well:

git push origin :refs/tags/3.3.1

Remember, 3.3.1 is the name of the tag we just deleted from our local repository.

After this the tag should be gone from the remote repository as well.

Happy coding!