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

前端 未结 8 800
天涯浪人
天涯浪人 2020-12-02 08:37

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 fetch-ing/pull

8条回答
  •  臣服心动
    2020-12-02 09:21

    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.

提交回复
热议问题