In Git, how can I delete multiple tags before pushing?
I know how to do it with one tag at a time. Not sure if it\'s possible to do multiple.
It will delete all matching tag patterns.
//Delete remote:
git push -d origin $(git tag -l "tag_prefix*")
// Delete local:
git tag -d $(git tag -l "tag_prefix*")
// Examples:
git tag -d $(git tag -l "v1.0*")
git push -d origin $(git tag -l "*v3.[2]*-beta*")
I found an easy way to do this if you have grep
and xargs
installed. I am shamelessly taking this from https://gist.github.com/shsteimer/7257245.
Delete all the remote tags with the pattern your looking for:
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
if you have too many tags (like in our case) you might want to do it like:
git tag -l > tags_to_remove.txt
then edit the file in your preferred editor - to review and remove the tags you want to keep (if any) and then run it locally
git tag -d $(cat ./tags_to_remove.txt)
and remotely:
git push -d origin $(cat ./tags_to_remove.txt)
To delete locally multiple tags: git tag:
git tag -d <tagname>...
So simply:
git tag -d TAG1 TAG2 TAG3
To delete multiple tags remotely: git push:
git push [-d | --delete] [<repository> [<refspec>...]]
So simply:
git push ${REMOTE_NAME:-origin} --delete TAG1 TAG2 TAG3
TL;DR:
git tag -d TAG1 TAG2 TAG3
git push origin -d TAG1 TAG2 TAG3
You can delete multiple tags with one command by specifying all the tags you want to delete
git tag -d 1.1 1.2 1.3
Then you can push all the deleted tags. Of course you can delete the tags with separate commands before pushing.
To push delete tags, just list all the tags you want to delete. The command is the same to delete one tag
git push --delete origin 1.1 1.2 1.3