Search code examples
gitgit-branchgit-tag

Git update tag without creating new branch?


I have a tag v1 set to an old commit. There is a bug with this version and I'd like to update it.

I ran get checkout v1. I have updated the code to fix this bug, then git-added and git-commited.

Now I would like to update the tag v1 to reference this new commit.

I tried git push -f origin v1. This does not work. I get the following response:

Everything up-to-date

Is there a way of achieving this? Preferably, I'd like to avoid creating a new branch, but if I have to, how can I avoid polluting the branch namespace? Can I just delete the branch afterwards?


Solution

  • I finally came up with a solution that works that doesn't require the creation of a new branch.

    1. git checkout tag_name

    2. Make local changes

    3. git add . and git commit -m "commit message"

    4. git tag -fa tag_name

    5. git push -f origin master --tags