Skip to content

Instantly share code, notes, and snippets.

@donnyquixotic
Last active November 30, 2023 23:57
Show Gist options
  • Save donnyquixotic/f1d8772030de0b67ad79aa64820e9a87 to your computer and use it in GitHub Desktop.
Save donnyquixotic/f1d8772030de0b67ad79aa64820e9a87 to your computer and use it in GitHub Desktop.
creates git alias 'vtag' that signs, verifies, and pushes local tag to remote
#!/bin/bash
# description:
# creates git alias 'vtag' that signs, verifies, and pushes local tag to remote
# usage: `git vtag <tag-name> [<target branch>]` e.g. `git vtag v1.2.3`
# params:
# <tag name> name of tag e.g. 'v1.2.3'
# <target branch> optional argument, branch to be tagged e.g. 'feature-branch', default is 'master'
# executed commands:
# - checkout master (or optionally <target branch>)
# - update local with remote
# - signs tag with annotation of tag name
# - verifies tag
# - pushes tag to remote
# assumptions:
# - GPG signing key is set in git config
# - repo permissions and git credentials allow pushing directly
# create alias:
# copypasta script below and execute in terminal or save file and run `chmod u+x $HOME/verifyTag.sh | . $HOME/verifyTag.sh`
git config --global alias.vtag '! _() {
if [ -z "${2}" ]; then
git checkout master
echo "verifying tag on master branch"
else
git checkout ${2}
echo "verifying tag on ${2} branch"
fi
git pull &&
git tag -s "$1" -m "$1" &&
git tag -v "$1" &&
git push origin "$1"
}; _'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment