Created
October 21, 2009 20:31
-
-
Save bdotdub/215432 to your computer and use it in GitHub Desktop.
rebasing git branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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