Created
May 13, 2009 14:38
-
-
Save knu/111055 to your computer and use it in GitHub Desktop.
How to mass-rename tags and push them with Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename tags named foo-bar-#.#.# to v#.#.# and push the tag changes | |
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done |
If you have a mixture of vx.y.z and x.y.z tags, the first command will add a v to your existing 'v' tags, creating vvx.y.z tags...
This shell script solves that issue:
#!/bin/bash
# Get all of the repo's tags
all_tags=$(git tag)
# Loop through all tags
for tag in $all_tags; do
# Only process tags not starting with "v"
if [[ $tag != v* ]]; then
# Create the vx.y.z tag
git tag v$tag $tag
# Delete the x.y.z tag
git tag -d $tag
# Pushes the new vx.y.z tag and deletes the x.y.z tag remotely
git push origin v$tag :$tag
fi
done
# Push all tags, shouldn't be necessary, just there as backup
git push --tags
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rename all
vx.y.z
tags tox.y.z
:git tag -l | while read t; do n="${t#?}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
Don't forget to turn off CI/CD, if it's based on the tags ;)