Skip to content

Instantly share code, notes, and snippets.

@donatj
Last active October 20, 2016 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donatj/7ae9246c964189a4c2f9 to your computer and use it in GitHub Desktop.
Save donatj/7ae9246c964189a4c2f9 to your computer and use it in GitHub Desktop.
Easily cherry pick one or more commits to a new branch
#!/bin/zsh
set -e
if [ $# -lt 3 ]
then
echo "Not Enough Arguments"
return 1
fi
START_BRANCH=`git rev-parse --abbrev-ref HEAD`
BASE="$1"
shift
NEW="$1"
shift
git stash -u
git checkout "$BASE"
git checkout -b "$NEW"
for var in "$@"
do
git cherry-pick "$var"
done
git checkout "$START_BRANCH"
git stash pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment