Skip to content

Instantly share code, notes, and snippets.

@mberlanda
Created July 26, 2018 15:38
Show Gist options
  • Save mberlanda/db0b0e449c6cacb01970ba59d107a217 to your computer and use it in GitHub Desktop.
Save mberlanda/db0b0e449c6cacb01970ba59d107a217 to your computer and use it in GitHub Desktop.
Rebase several branches
#!/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