How to rename a tag already pushed to a remote git repo

Here’s a quick git tip that i end up searching each time i need to do it. So i’m posting this here. There’s plenty of times i’ve added a tag, pushed to remote and realised that i’d named it wrong. Eg. 1.59 instead of 1.49 . To change it back you would need to add a new tag and push it,

$> git tag new_tag old_tag
$> git push --tags

Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:some.git
     * [new tag]         new_tag -> new_tag

Then delete the old tag from remote and local

$> git push origin :refs/tags/old_tag
$> git tag -d old_tag

But remember this can screw around with other people local repositories if they’ve already pulled before you make the change. So be careful!