Renaming git tags to fix ambiguity

Dec 23, 2016

Sometimes we need to rename a tag and push the changes to remote. This can possibly happen when a branch and tag has the same name. This ambiguity causes trouble during merge, diff etc. git commands.

If the tag hasn't been pushed to remote yet, then simply rename the tag and go on with your life.

> git tag new old
> git tag -d old

But if the tag is already out there, then there is no simple solution. One option is to rename the branch then push that to remote. Another option is to create a new tag as alias of the old tag. But the existing old tag (having the same name as a branch) will still cause trouble due to ambiguity. So the old one has to be removed. But that removal needs to be pushed to remote as well. The the procedure would look like below code.

> git tag new old
> git tag -d old
> git push origin :refs/tags/old
> git push --tags

But then whoever has already pulled from the remote repo will see the old tags still. Each of those users will have to prune their tags to remove the old one.

> git pull --prune --tags