Skip to content

Instantly share code, notes, and snippets.

@mariusae
Created September 30, 2015 22:20
Show Gist options
  • Save mariusae/5d159c9250631718106b to your computer and use it in GitHub Desktop.
Save mariusae/5d159c9250631718106b to your computer and use it in GitHub Desktop.
Restack a number of branches
#!/bin/bash
set -e
prev=$1
shift
for b
do
if ! git checkout $b >/dev/null 2>&1
then
echo "Failed to check out branch $v" >&2
exit 1
fi
echo "Rebasing $b onto $prev" >&2
if ! git rebase HEAD^ --onto $prev >/dev/null 2>&1
then
echo "Command \"git rebase HEAD^ --onto $prev\" failed" >&2
exit 1
fi
prev=$b
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment