Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script that rebases a bunch of branches and merges them into one.
# Usage: reb.sh branch_base new_base
set -e
git checkout --detach
oldbase=`git show-ref --heads -s "$1/base"`
branches=`git branch --list "$1/*"`
git checkout "$1/base"
git reset --hard $2
to_merge=""
for b in $branches
do
if [ $b == "$1/base" ] || [ $b == "$1/work" ]
then
continue
fi
# TODO check if branch is already ok (base is in)
git rebase --onto "$1/base" $oldbase $b
to_merge="$to_merge $b"
done
git checkout "$1/work"
git reset --hard "$1/base"
git merge --no-edit $to_merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment