Skip to content

Instantly share code, notes, and snippets.

@undergroundwires
Created May 23, 2020 20:35
Show Gist options
  • Save undergroundwires/aa2053be012f379faf506929d7182e8a to your computer and use it in GitHub Desktop.
Save undergroundwires/aa2053be012f379faf506929d7182e8a to your computer and use it in GitHub Desktop.
Rename all tags in GIT repository from "v.." (e.g. "v1.0.0" to without "v" e.g. "1.0.0")
#!/usr/bin/env bash
push_tag() {
local tag="$1"
echo "Pushing $tag"
git push origin "$tag"
}
delete_tag() {
local tag="$1"
echo "Deleting $tag"
git tag --delete "$tag"
git push --delete origin "$tag"
}
to_new_tag() {
local oldTag="$1"
printf "%s" ${oldTag:1}
}
rename_tag() {
local oldTag="$1"
if [[ ! "$oldTag" =~ ^v.* ]]; then
echo "Skipping tag: $oldTag"
return
fi
local newTag=$(to_new_tag "$oldTag")
echo "Renaming $oldTag to $newTag"
git tag "$newTag" "$oldTag"
delete_tag "$oldTag"
push_tag "$newTag"
}
main() {
git tag -l | while read oldTag
do
rename_tag "$oldTag"
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment