I have accumulated a lot of junk tags in my repositories. I want to delete all tags matching a given pattern, but not ALL tags, just those that match.
What is the best way to do this?
I'm on Windows (but I do have git-bash available if it is easier to do in a linux like way.. for instance I was thinking maybe xargs might be the way???)
is git for-each-ref the way to go here? I can't quite puzzle out how to use it though.
Note, I want to do this both for my local repo and for the origin.
For example, I do not want any tags that start with "someTag" as these were early tests. List with a pattern finds them, but delete with the same pattern fails
C:\ado\Info_11713_Test_Project>git tag -l someTag*
someTag-${Build.BuildNumber}
someTag-20230303.10
someTag-20230303.8
someTag-20230303.9
someTag-20230306.1
someTag-20230308.6
someTag-20230308.7
someTag-20230308.8
someTag-20230308.9
C:\ado\Info_11713_Test_Project>git tag -d someTag*
error: tag 'someTag*' not found.
Update: in git-bash I was able to do this which got rid of the local tags
HBIUSERS+H034561@W10DC2C2IC123 MINGW64 ~/lp/ado/Info_11713_Test_Project (main)
$ git tag -d `git tag -l | grep someTag-2`
Deleted tag 'someTag-20230303.10' (was a7142a6)
Deleted tag 'someTag-20230303.8' (was 2b27bab)
Deleted tag 'someTag-20230303.9' (was 2ac9c9a)
Deleted tag 'someTag-20230306.1' (was c05dd94)
Deleted tag 'someTag-20230306.2' (was 719b2b7)
Deleted tag 'someTag-20230306.3' (was 8aa2287)
Deleted tag 'someTag-20230306.4' (was df7bbfd)
Deleted tag 'someTag-20230308.2' (was fd54536)
Deleted tag 'someTag-20230308.3' (was 00ade5b)
Deleted tag 'someTag-20230308.4' (was 62f2166)
Deleted tag 'someTag-20230308.5' (was 916a394)
Deleted tag 'someTag-20230308.6' (was 93d43b3)
Deleted tag 'someTag-20230308.7' (was a85f46d)
Deleted tag 'someTag-20230308.8' (was 8af7d1f)
Deleted tag 'someTag-20230308.9' (was 71dd321)
but it didn't work for origin:
HBIUSERS+H034561@W10DC2C2IC123 MINGW64 ~/lp/ado/Info_11713_Test_Project (main)
$ git push --delete origin `git tag -l | grep someTag-2`
fatal: --delete doesn't make sense without any refs
Edit: xargs can do it. but it's really slow... is there a faster way?
for local:
git tag -l someTag-2* | xargs -I '{}' git tag -d '{}'
for remote:
git tag -l SomeTag-2* | xargs -I '{}' git push --delete origin '{}'