Created
May 21, 2023 15:10
-
-
Save PaulRBerg/cc9230fb993ea5f27aa328861f38e3c5 to your computer and use it in GitHub Desktop.
Checkout a temporary branch, cherry pick the provided commit(s), and finally switch to the provided branch name
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
# Checkout a temporaru branch `tmp`, cherry pick the provided commit(s), and | |
# finally switch to the provided branch name | |
# $1 = branch name | |
# $2 = first commit | |
# $3 = second commit for forming a range (optional) | |
function goCherryPick() { | |
if [ -z "$1" ]; then | |
echo "Branch name not provided, aborting" | |
return; | |
fi | |
if [ "$1" = "tmp" ]; then | |
echo "The branch name cannot be tmp" | |
fi | |
if [ -z "$2" ]; then | |
echo "Commit not provided, aborting" | |
return; | |
fi | |
git checkout -b tmp | |
if [ -z "$3" ]; then | |
git cherry-pick "$2" | |
else | |
git cherry-pick "$2"^.."$3" | |
fi | |
git branch -D "$1" | |
git branch -m "$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment