Last active
June 19, 2019 21:38
-
-
Save nikolareljin/7468a030918c933ef2664fc8b14af421 to your computer and use it in GitHub Desktop.
Rename old Tag in the existing repo with new name
This file contains hidden or 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
#!/bin/bash | |
#********************************************* | |
# Rename existing Tag in the remote Repo | |
# | |
# Use: | |
# rename_tag.sh <old_tag> <new_tag> | |
#********************************************* | |
pwd=${PWD} | |
old_tag=$1 | |
new_tag=$2 | |
if [[ -z $old_tag ]] || [[ -z $new_tag ]]; | |
echo "Old and New tag are required parameters" | |
exit() | |
fi; | |
if [[ ! -d ".git" ]]; then | |
echo "Not a git repository (${pwd})" | |
exit() | |
fi; | |
git fetch --all | |
git pull --all | |
git fetch origin --tags --force | |
git fetch origin --all | |
echo "Renaming Tags from ${old_tag} to ${new_tag}" | |
# Step 1: Create a new tag on the same commit point of old tag and push it, | |
git tag $new_tag $old_tag | |
git push --tags | |
# Step 2: Delete the old tag from local repo. | |
git tag -d $old_tag | |
# Step 3: Delete the old tag from remote repo. | |
git push origin :refs/tags/${old_tag} | |
# Push new tag to remote | |
git push origin refs/tags/${new_tag} | |
# You can verify the changes made, by executing the below command. It shows all remote tags: | |
echo "Check remote tags" | |
git ls-remote --tags origin | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment