Skip to content

Instantly share code, notes, and snippets.

@willvincent
Last active December 23, 2025 19:09
Show Gist options
  • Select an option

  • Save willvincent/03f2349f939e251f36b8da285a88c970 to your computer and use it in GitHub Desktop.

Select an option

Save willvincent/03f2349f939e251f36b8da285a88c970 to your computer and use it in GitHub Desktop.
Shell script to cherry pick commits for a hotfix to production
#!/bin/bash
set -e
# Important note: this will add a new patch release AND deploy
if [ $# -lt 2 ]; then
git fetch --all --tags
# Interactively get info
LATEST=$(git describe --tags production)
read -e -p "Enter the version to patch, or press return for default [$LATEST]: " VERSION
[ -z "$VERSION" ] && VERSION=$LATEST
COMMITS=""
echo -e "Enter a single commit to cherry-pick (you'll be able to enter more): \c"
while read -r COMMIT
do
[ -z $COMMIT ] && break
COMMITS="$COMMITS$COMMIT "
echo -e "Another commit (or ENTER if you're done): \c"
done
else
VERSION=$1
COMMITS=${@:2}
fi
if [[ $VERSION != v* ]]; then
echo "Version should be in the format vX.Y.Z"
exit 1
fi
set -x
git checkout $VERSION
# Cherry-pick the bugfix commit to this version
git cherry-pick $COMMITS
# Version bump, update CHANGELOG
npm run standard-version -r patch
# Get the new patch version, push tags
NEW_VERSION=$(git describe)
git push --follow-tags origin $NEW_VERSION
# Move the production branch to this new release
git branch -f production $NEW_VERSION
# Push production
git push -f origin production
git checkout master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment