How to Delete a Remote Git Tag?

The process of deleting a git tag from a remote repository varies based on your Git version. This guide will walk you through deleting tags in Git 1.8.0 and above, Git versions below 1.8.0, and common considerations for both.

TL;DR Summary

  1. Check Git version with git -v (or git --version);
  2. For Git v1.8.0+: git push -d <remote-name> refs/tags/<tag-name>;
  3. For Git < v1.8.0: git push <remote-name> :refs/tags/<tag-name>;
  4. Verify deletion of tags by checking the console output;
  5. Use shorter syntax by omitting "refs/" prefix;
  6. Clean up locally with git tag -d <tag-name>.

Deleting Remote Tags in Git 1.8.0 and Above

In Git versions 1.8.0 and above, removing a tag from a specific remote repository can be achieved by using the git push command with the -d flag (or --delete), like so:

# Git 1.8.0+
git push -d <remote-name> refs/tags/<tag-name>

Deleting Remote Tags in Git Versions Below 1.8.0

If you are using an earlier version of Git, using the git push command, you can specify the tag to remove by prefixing the tag name with a colon (:), like so:

# Git < 1.8.0
git push <remote-name> :refs/tags/<tag-name>

Common Considerations for Both Git Versions

Regardless of the Git version, keep these points in mind:

  1. Verifying Deletion of Remote Tags

    If the remote tag is removed successfully, an output like the following will be shown:

    To [email protected]:my-user/my-repo.git
     - [deleted]         v1.5.0
    

    If deletion of remote tag is unsuccessful, an output like the following will be shown:

    error: failed to push some refs to '[email protected]:my-user/my-repo.git'
    

    You can also verify if the tags have been deleted by listing all tags in your remote by using the following command:

    git ls-remote --tags origin
    
  2. Using a Shorter Syntax

    You may omit the "refs/" or "refs/tags/" prefix for a shorter syntax. At a minimum though, prefixing the tag name with "tags/" can help avoid accidentally removing branches with similar names.

  3. Local Cleanup

    Using git push command only removes the tag from the remote repository. To delete the tag locally as well, you must execute the following command:

    git tag -d <tag-name>
    

Examples

To delete a tag named "v1.5.0" from the remote "origin" as well as locally without risking unintended branch removals, you can use the following commands:

Git Version 1.8.0+

# delete remote tag
git push -d origin tags/v1.5.0

# delete local tag
git tag -d tags/v1.5.0

Git Version Below 1.8.0

# delete remote tag
git push origin :tags/v1.5.0

# delete local tag
git tag -d tags/v1.5.0

This post was published (and was last revised ) by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.