Created
July 18, 2011 15:19
-
-
Save rob-b/1089832 to your computer and use it in GitHub Desktop.
modified git-hack
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 | |
set -o errexit | |
CURRENT_BRANCH=`git branch | grep '\*' | awk '{print $2}'` | |
[[ -n `git config gitflow.branch.develop` ]] && DEVELOPMENT_BRANCH=`git config gitflow.branch.develop` | |
if [ -z ${DEVELOPMENT_BRANCH} ] | |
then | |
[[ -n `git branch | grep master` ]] && DEVELOPMENT_BRANCH=master | |
fi | |
if [ -z ${DEVELOPMENT_BRANCH} ] | |
then | |
echo "No 'master' branch and not using git-flow. Cannot tell where to rebase against" | |
exit 1 | |
fi | |
if [ "$DEVELOPMENT_BRANCH" = "$CURRENT_BRANCH" ] | |
then | |
echo "git-hack is designed for updating a topic branch but '$CURRENT_BRANCH' doesn't appear to be a topic branch" | |
exit 1 | |
fi | |
git checkout ${DEVELOPMENT_BRANCH} | |
git fetch | |
UPSTREAM=`git status | grep "# Your branch" |cut -d "'" -f 2` | |
if [ -z ${UPSTREAM} ] | |
then | |
echo "Cannot detect upstream" | |
git checkout ${CURRENT_BRANCH} | |
exit 1 | |
fi | |
if git status | grep -q "can be fast-forwarded" | |
then | |
git merge --ff "$UPSTREAM" | |
else | |
git rebase -p "$UPSTREAM" | |
fi | |
git checkout ${CURRENT_BRANCH} | |
git rebase ${DEVELOPMENT_BRANCH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment