Skip to content

Instantly share code, notes, and snippets.

@ryanemmm
Last active May 22, 2023 17:34
Show Gist options
  • Save ryanemmm/f59b288b811f6f651cabf37e2c684186 to your computer and use it in GitHub Desktop.
Save ryanemmm/f59b288b811f6f651cabf37e2c684186 to your computer and use it in GitHub Desktop.
move a git tag to HEAD
# bash/zsh
##
# git-retag.bash
# ** you're proabably not supposed to do this **
# move an existing tag from <old commit> to HEAD
#
# use it like this: `retag <tagname>`
#
# the tag you want to move
TAG=$1
# check for the tag, it should exist
# if it does not exist, complain then bail
CONTROL="$(git tag -l $TAG)"
if [[ -z $CONTROL ]]
then
echo 'could not find tag '"$TAG"'... bailing'
exit
fi
# tag exists... move it.
echo 'moving tag: '"$TAG"
#1. remove the tag from the remote
echo 'removing tag:'"$TAG"
git tag -d $1
git push origin :refs/tags/$1
#2. tag the current commit (HEAD)
echo 're-create tag '"$TAG"' on HEAD'
git tag -f $1
#3. push the update
echo 'push the updated tag'
git push --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment