Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Apr 16, 2013

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

This comment has been minimized.

Copy link

commented Apr 28, 2013

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

@jameswald

This comment has been minimized.

Copy link

commented Sep 22, 2013

thanks, this was helpful

@mrardon

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Dec 9, 2013

@mrardon Thanks, greatly appreciated link

@ghost

This comment has been minimized.

Copy link

commented Jun 5, 2014

cool ..thanks ..it was helpful

@lfbittencourt

This comment has been minimized.

Copy link

commented Jun 26, 2014

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

@jelledelaender

This comment has been minimized.

Copy link

commented Jul 11, 2014

Lovely! Thanks 👍

@itspolo

This comment has been minimized.

Copy link

commented Aug 27, 2014

👍

@jpswain

This comment has been minimized.

Copy link

commented Sep 28, 2014

@mrardon that link was awesome! thanks!! 😄

@nicholaslemay

This comment has been minimized.

Copy link

commented Oct 24, 2014

👍

@OOPMan

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Dec 9, 2014

Thanks for this

@simnalamburt

This comment has been minimized.

Copy link

commented Feb 19, 2015

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

This comment has been minimized.

@WenxiJin

This comment has been minimized.

Copy link

commented Mar 30, 2015

It is so convenient! Thanks very much.

@dminca

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

@RandomArray

This comment has been minimized.

Copy link

commented Aug 18, 2015

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jun 16, 2016

Very useful for cleaning up after testing some CI tools.

@chillyistkult

This comment has been minimized.

Copy link

commented Jun 2, 2017

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

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

@narzero

This comment has been minimized.

Copy link

commented Nov 5, 2017

@jmrobison, thanks, worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.