Created
April 13, 2021 16:20
-
-
Save takkaria/dfd0f1c1e11745f1c2f9f6f986e3a908 to your computer and use it in GitHub Desktop.
cherry-branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cherry-branch () { | |
if (test $# -lt 3); then | |
echo "Usage: cherry-branch [-p] <branch> <origin> <refs...>"; | |
echo " -p push to upstream with same name" | |
echo " <branch> new branch name" | |
echo " <origin> origin ref, e.g. origin/master" | |
echo " <refs> commit IDs to cherry-pick" | |
return; | |
fi | |
if (test "$1" == "-p"); then | |
PUSH=1 | |
shift | |
else | |
PUSH=0 | |
fi | |
local BRANCH_NAME=$1; | |
local ORIGIN_REF=$2; | |
shift 2; | |
git checkout -b $BRANCH_NAME || (echo "*** Checkout failed" && return) | |
git reset --hard $ORIGIN_REF || (echo "*** Reset failed" && return) | |
while (( "$#" )); do | |
git cherry-pick $1 || (echo "*** Cherry-picking failed" && return) | |
shift | |
done | |
if (test $PUSH -eq 1); then | |
git push --set-upstream origin $BRANCH_NAME | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment