Skip to content

Instantly share code, notes, and snippets.

@Gnurou
Created January 15, 2016 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gnurou/121666303a811436a412 to your computer and use it in GitHub Desktop.
Save Gnurou/121666303a811436a412 to your computer and use it in GitHub Desktop.
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