Skip to content

Instantly share code, notes, and snippets.

@bdotdub
Created October 21, 2009 20:31
Show Gist options
  • Save bdotdub/215432 to your computer and use it in GitHub Desktop.
Save bdotdub/215432 to your computer and use it in GitHub Desktop.
rebasing git branches
#!/bin/bash
# MAIN_BRANCH will use the first parameter or default to 'master'
MAIN_BRANCH=${1-master}
BRANCH=`git symbolic-ref HEAD | sed 's#refs/heads/##'`
BRANCH_HAS_DIRTY_FILES=`git diff-index --name-only HEAD --`
if [[ $MAIN_BRANCH = $BRANCH ]]; then
echo "You are already on the $BRANCH branch"
exit
fi
echo "Rebasing branch $BRANCH using $MAIN_BRANCH"
if [[ $BRANCH_HAS_DIRTY_FILES ]]; then
git stash
fi
git checkout dev
git pull
git checkout $BRANCH
git rebase dev
if [[ $BRANCH_HAS_DIRTY_FILES ]]; then
git stash pop
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment