Skip to content

Instantly share code, notes, and snippets.

@Otiel
Last active June 21, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Otiel/e1072dfd720685a75824abb4cd706eaa to your computer and use it in GitHub Desktop.
Save Otiel/e1072dfd720685a75824abb4cd706eaa to your computer and use it in GitHub Desktop.
Bash script to rename a git tag
#!/bin/bash
oldTag=$1
newTag=$2
tmpTag=$2-tmp
echo "* Running command: git tag $tmpTag $oldTag"
git tag $tmpTag $oldTag
echo
echo "* Running command: git tag -d $oldTag"
git tag -d $oldTag
echo
echo "* Running command: git push origin :refs/tags/$oldTag"
git push origin :refs/tags/$oldTag
echo
echo "* Running command: git tag $newTag $tmpTag"
git tag $newTag $tmpTag
echo
echo "* Running command: git tag -d $tmpTag"
git tag -d $tmpTag
echo
echo "* Running command: git push origin $newTag"
git push origin $newTag
@Otiel
Copy link
Author

Otiel commented Jun 21, 2019

Usage:

./rename-tag.sh oldTag newTag

This script uses a temporary tag in order to be able to rename tags by changing only the case of the characters. For instance, it is not possible to directly do:

git tag v1.0.0 V1.0.0
git tag -d V1.0.0

Because that will remove both tags V1.0.0 and v1.0.0.

Some useful links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment