Skip to content

Instantly share code, notes, and snippets.

@donatj

donatj/cp-branch

Last active Oct 20, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.