Categories
git git-tag

How do I delete a remote tag?

4359

How do I delete a Git tag that has already been pushed?

    7213

    You can push an ’empty’ reference to the remote tag name:

    git push origin :tagname
    

    Or, more expressively, use the --delete option (or -d if your git version is older than 1.8.0):

    git push --delete origin tagname
    

    Note that git has tag namespace and branch namespace so you may use the same name for a branch and for a tag. If you want to make sure that you cannot accidentally remove the branch instead of the tag, you can specify full ref which will never delete a branch:

    git push origin :refs/tags/tagname
    

    If you also need to delete the local tag, use:

    git tag --delete tagname
    

    Background

    Pushing a branch, tag, or other ref to a remote repository involves specifying “which repo, what source, what destination?”

    git push remote-repo source-ref:destination-ref
    

    A real world example where you push your master branch to the origin’s master branch is:

    git push origin refs/heads/master:refs/heads/master
    

    Which because of default paths, can be shortened to:

    git push origin master:master
    

    Tags work the same way:

    git push origin refs/tags/release-1.0:refs/tags/release-1.0
    

    Which can also be shortened to:

    git push origin release-1.0:release-1.0
    

    By omitting the source ref (the part before the colon), you push ‘nothing’ to the destination, deleting the ref on the remote end.

    8

    • 244

      +1 for both answering the question and explaining the general case, and detailing the unabridged syntax’s meaning

      Sep 14, 2012 at 19:03


    • 108

      And just in case someone wonders how to delete multiple tags at a time you simple list them using white space, e.g. git push --delete origin tag1 tag2. Same is valid for local tags deletion git tag -d tag1 tag2

      May 28, 2014 at 0:54

    • 10

      If tag name collides with a branch name you may end up with deleting your branch. Ha-ha. See the second answer – it’s more ecological

      – zuba

      Dec 26, 2016 at 9:56


    • 3

      It is also interesting to know that git tag -d `git tag` will delete all local tags. Same applies for git push --delete origin `git tag` assuming you pulled the remote tags locally. That was handy in a test environment.

      – DarkFranX

      Jul 31, 2018 at 15:15

    • 3

      The fact we’re at 6700+ upvotes and that it is this freaking complicated probably means it could be redesigned.

      – LMS5400

      Aug 31, 2021 at 21:31


    515

    A more straightforward way is

    git push --delete origin YOUR_TAG_NAME
    

    IMO prefixing colon syntax is a little bit odd in this situation

    5

    • 6

      I think this is the proper way… other syntax look more like hacks to me.

      Dec 24, 2012 at 17:45

    • 18

      This works. One addition: If you have a branch and a tag with the same name, you can put the word tag before your tag name to make sure you get the tag, not the branch.

      – andypaxo

      Mar 27, 2013 at 20:08

    • 11

      @andypaxo What the command takes is refspecs, the correct way would be prefixing the tags with refs/tags/, like this: refs/tags/v2.3.1.

      – p3lim

      Mar 13, 2015 at 5:04

    • I had ‘bad’ tag name created on remote server somehow, which had special characters, so I can’t sync with that, so simply removed that with your suggestion: git push –delete origin “service–<default>–151” , can’t remove it not with intellij, not with stash, not with sourceTree. Thanks !

      Apr 12, 2019 at 14:54

    • For those reading this long after the answer was posted, at the time, the (now accepted) answer did not have this content in it; later on this answer’s content was (very narrowly) suggested edit’d in to the accepted one. This is one of those weird edge cases where Stack Overflow’s “the best answer rises to the top system” kinda fails, on one hand I’m happy the accepted answer has the right information because most readers won’t look past the top answer, but I’m not thrilled as to how we got here… I hope future readers will not think this answer is just a copy/paste.

      – jrh

      Mar 5, 2020 at 16:17


    257

    If you have a remote tag v0.1.0 to delete, and your remote is origin, then simply:

    git push origin :refs/tags/v0.1.0
    

    If you also need to delete the tag locally:

    git tag -d v0.1.0
    

    See Adam Franco‘s answer for an explanation of Git’s unusual : syntax for deletion.

    6

    • 2

      this also works with jgit. the :tag shorthand does not work with jgit

      – rynop

      Sep 27, 2012 at 19:50

    • I got fatal: remote part of refspec is not a valid name in :/refs/tags/0.0.1 …?

      Sep 13, 2016 at 23:17

    • 3

      @ChaimEliyah you have a leading slash, maybe that’s your problem

      – Joffrey

      Oct 31, 2016 at 22:21

    • 5

      Better answer, as this also works if you have a branch and a tag that’s called the same.

      Feb 5, 2018 at 8:25

    • Just :tagname should work for the remote deletion.

      – Asclepius

      Feb 5, 2019 at 21:32