Skip to content

Instantly share code, notes, and snippets.

@shsteimer
Created October 31, 2013 21:10
Show Gist options
  • Star 76 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save shsteimer/7257245 to your computer and use it in GitHub Desktop.
Save shsteimer/7257245 to your computer and use it in GitHub Desktop.
Tip to delete tags by pattern
#delete all the remote tags with the pattern your looking for, ie. DEV-
git tag | grep <pattern> | xargs -n 1 -i% git push origin :refs/tags/%
#delete all your local tags
git tag | xargs -n 1 -i% git tag -d %
#fetch the remote tags which still remain
git fetch
@imsinu9
Copy link

imsinu9 commented Aug 2, 2016

git tag | xargs -n 1 -I% git tag -d %

@p00j4
Copy link

p00j4 commented Mar 12, 2018

thanks for the tip @shsteimer
a slight change is required:
xargs: illegal option -- i (tested on MAC)

uppercase I solves it.

@chinmaya-kony
Copy link

You can try this. It will delete all matching tag patterns.
E.g. for deleting tags starting with v1.0, use git tag -d $(git tag -l "v1.0*")

Delete remote:
git push -d $(git tag -l "tag_prefix*")
Delete local:
git tag -d $(git tag -l "tag_prefix*")

@luwes
Copy link

luwes commented Sep 16, 2018

Awesome @chinmaya-kony, this is the easiest I've seen. Thanks!
For the remote an origin is missing I think.
e.g git push -d origin $(git tag -l "*v3.[2]*-beta*")

@trygub
Copy link

trygub commented Jan 28, 2019

@luwes
git push origin --delete $(git tag -l "*v3.[2]*-beta*")

@kerryj89
Copy link

kerryj89 commented Jan 7, 2021

Run the following command If you get the message delete doesn't make sense without any refs when trying to delete remote tags:

git push origin --delete $(git ls-remote --tags | grep "tag_prefix.*[^}]$" | cut -f 2)

  • git ls-remote --tags will output all remote tags.
  • grep "*tag_prefix.*[^}]$" will ignore tags with annotated dereference operator "^{}" since including them errored out.
  • cut -f 2 keeps the tag name column only

@scottmathews
Copy link

scottmathews commented May 5, 2021

I accomplished this in posh-git PowerShell on Windows with this if anyone is needing to do the same:
git tag --list 'v[0-9].[1-9].*' --no-column | % { git tag -d $_; git push origin --delete $_ }

Note that I was specifying all builds from v1.1.0 and up, deleting them locally, and from the remote.

@danielsaidi
Copy link

Thank you for all these great commands!

Regarding @kerryj89 's version, you can modify it to work with any remote:

git push upstream --delete $(git ls-remote --tags upstream | grep "tag_prefix.*[^}]$" | cut -f 2)

@leoniralves
Copy link

Thanks @kerryj89. This worked fine on macOS! 👏

@githubtotusharTMA2
Copy link

You can try this. It will delete all matching tag patterns. E.g. for deleting tags starting with v1.0, use git tag -d $(git tag -l "v1.0*")

Delete remote: git push -d $(git tag -l "tag_prefix*") Delete local: git tag -d $(git tag -l "tag_prefix*")

Thank You @chinmaya-kony & @luwes.
Thank You All for the help🙏🏻

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