简体   繁体   中英

How to remove remote tags not on my local repository?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM