mlb mlb - 1 year ago 56
Git Question

In git, how do I sync my tags against a remote server?

Is there a way to keep my local git tags in lockstep with a remote's tags? That is -- not only get new tags when created (as usual, when

-ing), but also prune tags no longer on a remote and also delete existing tags when someone else
git push -f
's a tag.
I know I can
git fetch remotename
followed by
git remote prune remotename
to achieve similar behaviour for branches.

mlb mlb
Answer Source

A bit of research has shown that git has no way to tell the difference between local or foreign tags (all tags go to .git/refs/tags/). Therefore, it is not possible to determine the difference between locally created tags and prune-able remote tags. The options, are then reduced to: having an ever growing set of tags, or only the tags that are on the server.

git push --tags origin && \
git tag | xargs -n1 git tag -d && \
git fetch --tags

Drop the first line for the latter behaviour, and could be potentially git alias'd for frequent usage.

An alternative would be to create a branch (as they can be identified as local/remote) at a tag point and are never write to it again. Then using remotename/branchname as a tag to checkout would keep tags in sync (in addition to git fetch and git remote prune remotename).

Either way is a hack, and the "right" answer is to stop changing tags all the time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download