Skip to content

Instantly share code, notes, and snippets.

@knu
Created May 13, 2009 14:38
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save knu/111055 to your computer and use it in GitHub Desktop.
Save knu/111055 to your computer and use it in GitHub Desktop.
How to mass-rename tags and push them with Git
# 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
@SofiaSousa
Copy link

Renamed all my x.y.z tags to vx.y.z, thanks!

@bendem
Copy link

bendem commented Feb 18, 2019

you can greatly speed this up by pushing and pruning all remote tags at once:

# make sure your tags are up to date
git fetch origin
# rename all tags
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git tag -d $t; done
# synchronise with the server
git push --tags --prune origin refs/tags/*

@tomblenz
Copy link

you can greatly speed this up by pushing and pruning all remote tags at once:

# make sure your tags are up to date
git fetch origin
# rename all tags
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git tag -d $t; done
# synchronise with the server
git push --tags --prune origin refs/tags/*

no matches found: :refs/tags/*

@zkrige
Copy link

zkrige commented Aug 28, 2020

This changes x.y.z to x/y/z, but won't delete tags that are already in new format

# make sure your tags are up to date
git fetch origin
# rename all tags
git tag -l | while read t; do n=$(echo $t | sed "s?\.?/?g"); if [[ "$n" != "$t" ]]; then git tag $n $t; git tag -d $t; git push origin :refs/tags/$t ; done

@llinardos
Copy link

This changes build/n to build/0n (e.g.: build/8 -> build/08).

git tag -l | while read t; do n=$(echo $t | sed "s?\/?/0?g"); git tag $n $t; git tag -d $t; done

@PavelSavushkinMix
Copy link

Rename all vx.y.z tags to x.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 ;)

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