Search code examples
gittagsrelease-management

Update a remote tag in git (to mark latest stable release)


Even though there are other possibilities for marking code as latest stable (such as release branches), I was wondering why not use a tag for marking the latest stable (even across major version numbers or any other versioning scheme).

The concept of tag in git is anyway not friendly to this use since tags cannot be updated (moved around as the doc says). So even if I delete and recreate an annotated tag elsewhere locally, I get an error when trying to push it to the remote. Is there any way to update the remote tag directly from a local one with the same name?


Solution

  • Of course there is.

    git push --tags -f
    

    force pushes tags. So if you update it locally, it also gets updated on the remote.

    The above solution is risky, though, since it pushes ALL tags and overwrites them. Say your tag is named

    stable
    

    then you can do the following

    First, delete the remote tag

    git push origin :refs/tags/stable
    

    Next, push in the standard way

    git push --tags
    

    Or... as a one-liner

    git push origin stable:refs/tags/stable