Software Developer

Bulk Delete Tags in Local Git Repo and GitHub.com

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

By

We've 2 Responses

  1. 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”

    git tag --list '*.2' | xargs -I {} git push origin :{}
    

    And for syncing the local repo with the remote then, so removing the tags locally too:

    git fetch --prune origin '+refs/tags/*:refs/tags/*'
    
    avatar

Leave a Reply to Dennis Cancel reply

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]