Created
June 24, 2021 09:19
-
-
Save kangmasjuqi/5a6dd69dd449f8e07b03e599d2136a36 to your computer and use it in GitHub Desktop.
cherry.sh - apply specific changes into specific branch and then push that changes into remote repo afterward
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
# bismillah - shollallahu 'alaa Muhammad | |
# | |
# assume you are working on your local working branch | |
# where the whole code is on your hand | |
# then you want to apply specific changes (commitId) into specific branch | |
# and then push that changes into remote repo afterward | |
# | |
# how to use : ./cherry.sh TARGET_BRANCH_NAME COMMIT_ID | |
# | |
LOCAL_WORKING_BRANCH=marjuqi-develop | |
TARGET_BRANCH_NAME=$1 | |
COMMIT_ID=$2 | |
echo "##### Step 0 : safely stash our changes in the working branch : $LOCAL_WORKING_BRANCH.." | |
git checkout $LOCAL_WORKING_BRANCH && git stash | |
echo "##### Step 1 : checking out to branch $TARGET_BRANCH_NAME .." | |
git checkout $TARGET_BRANCH_NAME | |
echo "##### Step 2 : cherry-picking $COMMIT_ID .." | |
git cherry-pick $COMMIT_ID | |
echo "##### Step 3 : push the cherry-picked changes into remote branch of $TARGET_BRANCH_NAME" | |
git push | |
echo "##### Step 4 : heading back to the working branch : $LOCAL_WORKING_BRANCH.." | |
git checkout $LOCAL_WORKING_BRANCH && git stash pop | |
echo "##### DONE. :) " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment