Last active
June 29, 2018 21:05
-
-
Save alanzhaonys/fa8bd8ccde52c598d2d88be78d9a89c7 to your computer and use it in GitHub Desktop.
Cherry pick a commit to all other branches in a project, specify --skip-master as 2nd parameter to skip master branch. *** BE CAREFUL: *** this script assumes your branches are clean and there will be no pending merges when it's doing the `git pull` prior to cherry picking. It could fuck up your code, I take no responsibilities.
This file contains hidden or 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
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo "Enter a commit id (run \`git log\` to see commit history)" | |
echo "Example: ./batch-cherry-pick.sh [commit id] --skip-master" | |
exit | |
fi | |
# Commmit id parameter | |
readonly commit=$1 | |
# --skip-master parameter | |
readonly skip_master=$2 | |
# Current branch | |
readonly current_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') | |
# The branch of the original commit is made under | |
readonly originating_branch=develop | |
if [ "$current_branch" != "$originating_branch" ] ; then | |
echo "Your are not in $originating_branch branch" | |
exit | |
fi | |
for branch in `git branch --list|sed 's/\*//g'`; | |
do | |
if [ "$branch" != $originating_branch ] ; then | |
if [ "$skip_master" == "--skip-master" ] \ | |
&& [ "$branch" == "master" ] ; then | |
continue | |
fi | |
git pull | |
git checkout $branch | |
git cherry-pick -x $commit | |
git push | |
fi | |
done | |
git checkout $originating_branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment