Skip to content

Instantly share code, notes, and snippets.

@matthewmccullough
Created April 1, 2011 20:29
Show Gist options
  • Star 91 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save matthewmccullough/898798 to your computer and use it in GitHub Desktop.
Save matthewmccullough/898798 to your computer and use it in GitHub Desktop.
Script to delete all tags both locally and remotely
for t in `git tag`
do
git push origin :$t
git tag -d $t
done
@mazzarito
Copy link

My update to this, deletes last 120 tags

num=0
for t in `git tag`
do
  if [ "$num" -ge 120 ]
    then
      break
  fi
  git push origin :$t
  git tag -d $t
  num=`expr $num + 1`
  echo "Removed $t"
done```

@mauris
Copy link

mauris commented Apr 28, 2013

In case you're looking for a Windows Command version, look at https://gist.github.com/thephpdeveloper/5475696

@jameswald
Copy link

thanks, this was helpful

@mrardon
Copy link

mrardon commented Nov 15, 2013

This was too slow for me - have a look at this to make it happen much faster http://blog.siyelo.com/how-to-bulk-delete-remote-git-tags

@rafi
Copy link

rafi commented Dec 9, 2013

@mrardon Thanks, greatly appreciated link

Copy link

ghost commented Jun 5, 2014

cool ..thanks ..it was helpful

@lfbittencourt
Copy link

I've made a (faster) Ruby version inspired in your script. Thanks!

@jelledelaender
Copy link

Lovely! Thanks 👍

@itspolo
Copy link

itspolo commented Aug 27, 2014

👍

@jpswain
Copy link

jpswain commented Sep 28, 2014

@mrardon that link was awesome! thanks!! 😄

@nicholaslemay
Copy link

👍

@OOPMan
Copy link

OOPMan commented Nov 19, 2014

mrardons version didn't work for me. Luckily I only had a few tags so I just used the slow version.

@jakeasmith
Copy link

Thanks for this

@simnalamburt
Copy link

First line removes all tags remotly, the next line removes all tags locally

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

@nicholascross
Copy link

@WenxiJin
Copy link

It is so convenient! Thanks very much.

@dminca
Copy link

dminca commented Jun 22, 2015

@simnalamburt that looks soo destructive, but I like it 😀

@RandomArray
Copy link

@mauris that Gist is a 404 now.

For anybody looking for a Windows version, I created a Gist below with the commands I used to remove all Tags on Windows. The Linux command xargs would not work. I would get an xargs: cannot fork: Permission denied error. Figured out I need to use the FOR command in Windows.

https://gist.github.com/RandomArray/fdaa427878952d9768b0

@jmrobison
Copy link

jmrobison commented Apr 26, 2016

We use bitbucket to host our git repo, and the commands above didn't work. This one did:

for tag in `git tag -l`
do
  git tag -d $tag
  git push -v origin :refs/tags/$tag
done

Reference: https://confluence.atlassian.com/bitbucket/how-do-i-remove-or-delete-a-tag-from-a-git-repo-282175551.html

@brendan-munro
Copy link

Very useful for cleaning up after testing some CI tools.

@chillyistkult
Copy link

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

fatal: --delete doesn't make sense without any refs

@narzero
Copy link

narzero commented Nov 5, 2017

@jmrobison, thanks, worked!

@numediaweb
Copy link

For the issue with --delete doesn't make sense without any refs here's how I delete all the tags for 1.3.* :
git ls-remote --tags origin | awk '/^(.*)(1\.3\.\d+)$/ {print ":" $2}' | xargs git push origin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment