Created
July 26, 2018 15:38
-
-
Save mberlanda/db0b0e449c6cacb01970ba59d107a217 to your computer and use it in GitHub Desktop.
Rebase several branches
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
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
PROJECT_DIR=$(git rev-parse --show-toplevel) | |
# Base branch for rebasing | |
BASE_BRANCH="master" | |
# Enter here the name of the branches to rebase | |
# no commas, double quotes | |
BRANCHES_TO_REBASE=( | |
"my-branch-1" | |
"my-branch-2" | |
) | |
function main { | |
cd ${PROJECT_DIR} | |
git checkout ${BASE_BRANCH} | |
git pull | |
for BRANCH in "${BRANCHES_TO_REBASE[@]}"; do | |
echo "Rebasing ${BRANCH} ..." | |
git checkout ${BRANCH} | |
echo "Remove untracked files: e.g. integration_test/ dir" | |
git clean -fd | |
git rebase ${BASE_BRANCH} | |
git push --force-with-lease | |
git checkout ${BASE_BRANCH} | |
echo "${BRANCH} successfully rebased" | |
done | |
echo "Done" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment