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 grep
ing, sort
ing, tail
ing or head
ing you want (e.g. grep -P "my_regex" | sort | head -n -200
etc) :
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
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
).
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 " ")