Skip to content

Instantly share code, notes, and snippets.

@terrycojones
Created September 19, 2011 17:07
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 terrycojones/1226965 to your computer and use it in GitHub Desktop.
Save terrycojones/1226965 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x -e
# update master first
git checkout master
git pull upstream master
git push origin master
REVIEW_BRANCH_NAME=_reviewbranch
PREREQUISITE_BRANCH_NAME=_prerequisite
case $# in
1) BRANCH="$1";;
2) BRANCH="$1"; PREREQUISITE="$2";;
*) echo "Usage: `basename $0` branch [prerequisite]" >&2; exit 1;;
esac
parts=($(echo "$BRANCH"|tr : '\n'))
BRANCH_REMOTE=${parts[0]}
BRANCH_NAME=${parts[1]}
# delete previous review branches
git branch -D $REVIEW_BRANCH_NAME | true
git branch -D $PREREQUISITE_BRANCH_NAME | true
git fetch $BRANCH_REMOTE $BRANCH_NAME:$REVIEW_BRANCH_NAME
if [ $PREREQUISITE ]
then
parts=($(echo "$PREREQUISITE"|tr : '\n'))
PREREQUISITE_REMOTE=${parts[0]}
PREREQUISITE_NAME=${parts[1]}
git fetch $PREREQUISITE_REMOTE $PREREQUISITE_NAME:$PREREQUISITE_BRANCH_NAME
REBASE_BRANCH=$PREREQUISITE_BRANCH_NAME
else
REBASE_BRANCH=master
fi
# checkout to the new branch and rebase
git checkout $REVIEW_BRANCH_NAME
git rebase $REBASE_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment