Вопрос: Как удалить тег git remote?

Как удалить тег git, который уже был нажат?




Вам просто нужно нажать «пустую» ссылку на имя удаленного тега:

git push origin :tagname

Или, более выразительно, использовать --deleteвариант (или -dесли ваша версия git старше 1.8.0):

git push --delete origin tagname

Если вам также необходимо удалить локальный тег, используйте:

git tag --delete tagname

Задний план

Нажатие ветки, тега или другого ref в удаленный репозиторий включает указание «push где, какой источник, какой пункт назначения?»

git push where-to-push source-ref:destination-ref

Пример реального мира, когда вы нажимаете свою ведущую ветвь на главную ветвь оригинала:

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

Который из-за путей по умолчанию может быть сокращен до:

git push origin master:master

Теги работают одинаково:

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

Который также может быть сокращен до:

git push origin release-1.0:release-1.0

Опуская исходную ссылку ref (часть перед двоеточием), вы нажимаете «ничего» на место назначения, удаляя ref на удаленном конце.


Более простым способом является

git push --delete origin YOUR_TAG_NAME

Синтаксис синтаксиса демона ИМО немного странный в этой ситуации


Если у вас есть удаленный тег v0.1.0для удаления, а ваш пульт дистанционного управления origin, то просто:

git push origin :refs/tags/v0.1.0

Если вам также необходимо удалить тег локально:

git tag -d v0.1.0

Видеть Адам Франко ответ для объяснения необычного :синтаксис для удаления.


Удалите все локальные теги и получите список удаленных тегов. :

git tag -l | xargs git tag -d
git fetch

Удалите все удаленные теги

git tag -l | xargs -n 1 git push --delete origin

Очистка локальных тегов

git tag -l | xargs git tag -d


To remove the tag from the remote repository:

git push --delete origin TAGNAME

You may also want to delete the tag locally:

git tag -d TAGNAME


From your terminal, do this:

git fetch
git tags
git tag -d {tag-name}
git push origin :refs/tags/{tag-name}

Now go to Github.com and refresh, they disappear.


Just notice that, if you have a remote branch named as a remote tag, these commands are ambiguous:

git push origin :tagname
git push --delete origin tagname

So you must use this command to delete the tag:

git push origin :refs/tags/<tag>

and this one to delete the branch:

git push origin :refs/heads/<branch>

If not, you would get an error like this:

error: dst refspec <tagname> matches more than one.
error: failed to push some refs to '<repo>'


If you have created a tag called release01 in a Git repository you would remove it from your repository by doing the following:

git tag -d release01 
git push origin :refs/tags/release01 

To remove one from a Mercurial repository:

hg tag --remove featurefoo

Please reference https://confluence.atlassian.com/pages/viewpage.action?pageId=282175551


The other answers point out how to accomplish this, but you should keep in mind the consequences since this is a remote repository.

The git tag man page, in the On Retagging section, has a good explanation of how to courteously inform the remote repo's other users of the change. They even give a handy announcement template for communicating how others should get your changes.


Up to 100x faster method for thousands of remote tags

After reading through these answers while needing to delete over 11,000 tags, I learned these methods relying or xargs take far too long, unless you have hours to burn.

Struggling, I found two much faster ways. For both, start with git tag or git ls-remote --tags to make a list of tags you want to delete on the remote. In the examples below you can omit or replace sorting_proccessing_etc with any greping, sorting, tailing or heading you want (e.g. grep -P "my_regex" | sort | head -n -200 etc) :

This first method is by far the fastest, maybe 20 to 100 times faster than using xargs, and works with a least several thousand tags at a time.

git push origin $(< git tag | sorting_processing_etc \
| sed -e 's/^/:/' | paste -sd " ") #note exclude "<" for zsh

How does this work? The normal, line-separated list of tags is converted to a single line of space-separated tags, each prepended with : so . . .

tag1   becomes
tag2   ======>  :tag1 :tag2 :tag3

Using git push with this format tag pushes nothing into each remote ref, erasing it (the normal format for pushing this way is local_ref_path:remote_ref_path).

Method two is broken out as a separate answer elsewhere on this same page

After both of these methods, you'll probably want to delete your local tags too. This is much faster so we can go back to using xargs and git tag -d, which is sufficient.

git tag | sorting_processing_etc | xargs -L 1 git tag -d

OR similar to the remote delete:

git tag -d $(< git tag | sorting_processing_etc | paste -sd " ")


Delete local tag '12345'

git tag -d 12345

Delete remote tag '12345' (eg; GitHub version too)

git push origin :refs/tags/12345

alternative approach

git push --delete origin tagName
git tag -d tagName

enter image description here


Simple script to remove given tag from both local and origin locations. With a check if tag really exists.

if [ $(git tag -l "$1") ]; then
    git tag --delete  $1
    git push --delete origin $1

    echo done.
    echo tag named "$1" was not found

How to use:

  • Create shell script file (e.g. git-tag-purge.sh) and paste content.
  • chmod your script file to make it executable.
  • Make the script globally available
  • cd to your git project
  • Call script (e.g.
    $>git-tag-purge.sh tag_name