Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove remote tags not on my local repository?

Tags:

git

regex

grep

bash

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?

like image 556
mimoralea Avatar asked Oct 20 '22 00:10

mimoralea


1 Answers

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.

like image 62
Travis Avatar answered Oct 24 '22 10:10

Travis