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

前端 未结 8 776
天涯浪人
天涯浪人 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

    disclaimer this uses git internals (some may argue that the filesystem is a git interface, but that's for another day :D)

    # Blow away all local tags, this will remove any that are tagged locally
    # but are not on the remote
    rm .git/refs/tags/*
    
    # Download all the tags from the remote
    git fetch --tags
    
    0 讨论(0)
  • 2020-12-02 09:23

    Here's an alternative solution:

    git fetch -p +refs/tags/*:refs/tags/*
    

    From the git fetch doc:

    -p --prune

    Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a --tags option. However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning.

    0 讨论(0)
提交回复
热议问题