Skip to content

Instantly share code, notes, and snippets.

@rob-b
Created July 18, 2011 15:19
Show Gist options
  • Save rob-b/1089832 to your computer and use it in GitHub Desktop.
Save rob-b/1089832 to your computer and use it in GitHub Desktop.
modified git-hack
#!/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