Skip to content

Instantly share code, notes, and snippets.

@boxrick
Created August 20, 2018 14:46
Show Gist options
  • Save boxrick/f0bac46ab90f8ec8f5e3f0512e049252 to your computer and use it in GitHub Desktop.
Save boxrick/f0bac46ab90f8ec8f5e3f0512e049252 to your computer and use it in GitHub Desktop.
Rename git tag from old to new. Local and upstream
# Simple script to remove the pre-pended 'v' from current git repo and push this upstream.
for old_tag in $(git tag)
do
# remove v from tag
new_tag=$(echo "${old_tag//v}")
# If the tags don't match then do our rename
if [ "$old_tag" != "$new_tag" ]
then
echo 'Tags dont match, removing pre-pended v'
echo "$old_tag $new_tag"
# Copy tag
git tag $new_tag $old_tag
# Push new tag
git push --tags
# Delete old from local and remote
git tag -d $old_tag
git push origin :refs/tags/$old_tag
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment