Skip to content

Instantly share code, notes, and snippets.

@dingram
Created July 1, 2010 15:41
Show Gist options
  • Save dingram/460135 to your computer and use it in GitHub Desktop.
Save dingram/460135 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# git-svn-rebase-all
# by Dave Ingram <http://github.com/dingram/>
#
SHELL=${SHELL:-/bin/bash}
curbranch=$(git symbolic-ref HEAD 2>/dev/null)
if [ $? -eq 0 ]; then
curbranch=${curbranch##*/}
else
curbranch=$(git name-rev --name-only --always HEAD)
fi
git co master
git svn rebase &&
for branch in $(git br | grep -v \\\*); do
git co "$branch"
if [[ -n "$( git "config branch.$branch.remote" )" ]]; then
# remote tracking branch
git svn rebase
continue
fi
fromrev="$( git log --pretty=tformat:%H $branch '^master' | tail -1 )"
if [[ -z "$fromrev" ]]; then
git merge --ff-only --no-stat master || ( echo "Something went wrong while rebasing $branch"; echo "Exit this shell to continue with other branches"; $SHELL )
else
git rebase --onto master "${fromrev}~1" "$branch" || ( echo "Something went wrong while rebasing $branch"; echo "Exit this shell to continue with other branches"; $SHELL )
fi
done
git co "$curbranch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment