Skip to content

Instantly share code, notes, and snippets.

@bstillitano
Last active February 26, 2021 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstillitano/9e916dc7caa22077215e961387a7c63c to your computer and use it in GitHub Desktop.
Save bstillitano/9e916dc7caa22077215e961387a7c63c to your computer and use it in GitHub Desktop.
Simple shell script that allows you to move a git tag without having to manually remove it. This script guides you through without requiring any knowledge of git.
#!/bin/bash
echo -e "Hi $(whoami) 👋, this script allows you to move an existing git tag to the latest commit on your current branch and then pushes it to the remote. Are you sure you want to proceed? [y/n]"
read proceedWithMove
if [ $proceedWithMove == y ] || [ $proceedWithMove == Y ]
then
echo -e "\n\nWhat directory is your git branch in? This script will cd in for you and use that as the working directory. This should be relative to the root folder of your machine. For example, if your repository is at ~/Users/Brandon/iOS then you should enter /Users/Brandon/iOS. If you're currently in the right folder, leave this blank."
read directory
if [ -z "$directory" ]
then
echo -e "\n\nOk, staying in your current working directory."
else
echo -e "\n\nMoving into $directory"
cd ~
cd $directory
fi
echo -e "\n\nOk, let's move your tag. What tag did you want to move?"
read tagToMove
echo -e "\n\nAre you sure you want to move '$tagToMove' to the latest commit on your current branch? [y/n]"
read reallyMoveTag
if [ $reallyMoveTag == y ] || [ $reallyMoveTag == Y ]
then
echo -e "\n\nOk, what tag message would you like? You can leave this blank if you'd like."
read tagMessage
echo -e "\n\nYassss queen, going ahead and moving the tag. This shouldn't take too long."
git push origin :refs/tags/$tagToMove
git tag -fa $tagToMove -m "$tagMessage"
git push origin refs/tags/$tagToMove
else
echo -e "\n\nOk, you had me going, I thought we were about to move some tags. Bye ✌️"
fi
else
echo -e "\n\nOk, big sad, bye 😔"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment