These are commands to delete version tags in bulk, both in a local Git repository, and a remote repo, such as GitHub.com. You can delete all tags, or use regexp to delete a select group of tags. You may modify the examples below to suit your needs. These commands work using Git Bash.
1. Bulk Delete Tags in Local Git Repo
Delete all tags in the local repository:
git tag -d `git tag | grep -E '.'`
Examples of deleting a select group of tags:
Delete all tags that end with “.2“:
git tag -d `git tag | grep -E '^*\.2$'`
Delete all tags that end with a letter:
git tag -d `git tag | grep -E '^*[a-zA-Z]$'`
Delete all tags that contain two or more decimal points, such as 1.2.3.
git tag -d `git tag | grep -E '^.\..\..'`
2. Bulk Delete Tags in a Remote Git Repo, such as GitHub.com
Delete all tags on GitHub.com:
git ls-remote --tags origin | awk '/^(.*)(\s+)(.*[a-zA-Z0-9])$/ {print ":" $2}' | xargs git push origin
Delete all tags on GitHub.com that end with “.2”
git ls-remote --tags origin | awk '/^(.*)(.\.2)$/ {print ":" $2}' | xargs git push origin
Delete all tags that end with a letter:
git ls-remote --tags origin | awk '/([a-zA-Z])$/ {print ":" $2}' | xargs git push origin
Delete all tags that contain two or more decimal points, such as 1.2.3.
git ls-remote --tags origin | awk '/^(.*)(.\..\..)$/ {print ":" $2}' | xargs git push origin
Tony Mann
March 29th, 2017 at 2:38 pm
Very helpful, thanks! For the remote calls, add the –refs options to avoid seeing tag references.
Dennis
January 17th, 2019 at 7:08 am
The following is what I was going with, when you only need simple patterns and not the regex power:
Eg. for deleting all tags ending with “.2”
And for syncing the local repo with the remote then, so removing the tags locally too: