How to rename a tag in Git

Well, first of — you can’t. You have to map a new tag to the old one then delete the old tag. Let’s assume we currently have a tag called “old_tag” and we want to replace it with a tag named “new_tag”.

To link the new tag to the old one:

[code lang=”bash”]git tag new_tag old_tag[/code]

This creates a new_tag that references the commit made by old_tag.

Now we need know how to delete the old tag in Git.

[code lang=”bash”]git tag -d old_tag[/code]

Bye old_tag. Now the thing about git is it doesn’t let you delete the tag on the remote server just as a precaution. Now you can’t do something like “git push –tags origin master” to delete the tag from the remote server.

Here’s how to do it:

[code lang=”bash”]git push origin :refs/tags/old_tag[/code]

You need to explicitly state that you want that reference updated. This will delete the tag in the remote server.