Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Forked from miguelgonz/git sync
Created February 28, 2016 19:33
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 thomasdarimont/efb022275ab9353b61d4 to your computer and use it in GitHub Desktop.
Save thomasdarimont/efb022275ab9353b61d4 to your computer and use it in GitHub Desktop.
git sync
#!/bin/sh
#To make use of this just copy it to your path, +x it, and do git sync
MAIN_BRANCH="develop"
CURRENT_CHANGES=`git status --porcelain`
CURRENT_BRANCH=`git symbolic-ref -q --short HEAD`
if [ "$CURRENT_CHANGES" != "" ]; then
git stash --include-untracked
fi
if [ "$CURRENT_BRANCH" != "$MAIN_BRANCH" ]; then
git checkout $MAIN_BRANCH
fi
git fetch upstream
git merge upstream/$MAIN_BRANCH
if [ "$CURRENT_BRANCH" != "$MAIN_BRANCH" ]; then
git checkout $CURRENT_BRANCH
fi
git rebase $MAIN_BRANCH
if [ "$CURRENT_CHANGES" != "" ]; then
git stash pop
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment