I would like to have origin match my local tags. This is not to be confuse with pruning local tags, but remote instead.
To prune local tags and make my local repository match origin I do:
git tag -l | xargs git tag -d
git fetch
I cleaned the tags locally and I would like to push and remove what is not up in remote.
I have been doing it manually like:
git tag -l | grep -v "[^v2]" | xargs git tag -d # remove local tags that don't match a pattern
git push origin :refs/tags/2.2.15 # manually remove those tags on remote
git push origin :refs/tags/2.2.16
git push origin :refs/tags/2.2.17
git push origin :refs/tags/2.2.18
...
But with so many tag I feel like this could be done differently. Question is then, How to remove from a remote repository those tags that you do not have locally?
Just tested it on a remote repo and it works fine.
I used cut
instead of grep
, and compared the remote tags against the local ones, then removed the remote ones that differed.
git ls-remote --tags origin | cut -f 2 | xargs basename | comm -23 - <(git tag) | awk '{print ":refs/tags/" $0}' | xargs git push origin
Not the most elegant thing in the world, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With