Skip to content

Instantly share code, notes, and snippets.

@pestilence669
Last active April 10, 2017 23:50
Show Gist options
  • Save pestilence669/9a0f19b90d16b4240537 to your computer and use it in GitHub Desktop.
Save pestilence669/9a0f19b90d16b4240537 to your computer and use it in GitHub Desktop.
Fetch upstrem master and rebase
#!/bin/bash
# vim: set ts=4 sw=4 noet:
# get current checked out branch
B=`git rev-parse --abbrev-ref HEAD`
if [ $? -ne 0 ]; then # problem, likely not a git repo
exit -1 # leave whatever error occurred alone
fi
# sync from the upstream origin
git fetch upstream
# switch to master, if we aren't already there
if [ $B != "master" ]; then
git co master
fi
git pull --rebase upstream master || exit -1
# switch back and rebase, if we didn't have master checked out
if [ $B != "master" ]; then
git co $B
git rebase master $B
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment