How do you rename a Git tag? How do you rename a Git tag? git git

How do you rename a Git tag?


Here is how I rename a tag old to new:

git tag new oldgit tag -d oldgit push origin new :old

The colon in the push command removes the tag from the remote repository. Ifyou don't do this, Git will create the old tag on your machine when you pull.Finally, make sure that the other users remove the deleted tag. Please tellthem (co-workers) to run the following command:

git pull --prune --tags

Note that if you are changing an annotated tag, you need ensure that thenew tag name is referencing the underlying commit and not the old annotated tagobject that you're about to delete. Therefore, use git tag -a new old^{}instead of git tag new old (this is because annotated tags are objects whilelightweight tags are not, more info in this answer).


The original question was how to rename a tag, which is easy: first create NEW as an alias of OLD: git tag NEW OLD then delete OLD: git tag -d OLD.

The quote regarding "the Git way" and (in)sanity is off base, because it's talking about preserving a tag name, but making it refer to a different repository state.


In addition to the other answers:

First you need to build an alias of the old tag name, pointing to the original commit:

git tag new old^{}

Then you need to delete the old one locally:

git tag -d old

Then delete the tag on you remote location(s):

# Check your remote sources:git remote -v# The argument (3rd) is your remote location,# the one you can see with `git remote`. In this example: `origin`git push origin :refs/tags/old

Finally you need to add your new tag to the remote location. Until you have done this, the new tag(s) will not be added:

git push origin --tags

Iterate this for every remote location.

Be aware, of the implications that a Git Tag change has to consumers of a package!