Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created July 27, 2011 09:26
Show Gist options
  • Save jakearchibald/1109001 to your computer and use it in GitHub Desktop.
Save jakearchibald/1109001 to your computer and use it in GitHub Desktop.
alias gs='git status'
alias gai='git add --interactive'
alias gsvn='git svn'
alias gsup='gsvn fetch && gsvn rebase'
alias gsp='gsup && gsvn dcommit'
alias gf='git fetch'
alias gr='git rebase'
alias gp='gup && git push'
alias gff='git flow feature'
alias gfr='git flow release'
function gc {
git commit -am "$1"
gs
}
function goops {
git commit -a --amend
gs
}
function gup
{
# subshell for `set -e` and `trap`
(
set -e # fail immediately if there's a problem
# fetch upstream changes
git fetch
BRANCH=$(git describe --contains --all HEAD)
if [ -z "$(git config branch.$BRANCH.remote)" -o -z "$(git config branch.$BRANCH.merge)" ]
then
echo "\"$BRANCH\" is not a tracking branch." >&2
exit 1
fi
# create a temp file for capturing command output
TEMPFILE="`mktemp -t gup.XXXXXX`"
trap '{ rm -f "$TEMPFILE"; }' EXIT
# if we're behind upstream, we need to update
if git status | grep "# Your branch" > "$TEMPFILE"
then
# extract tracking branch from message
UPSTREAM=$(cat "$TEMPFILE" | cut -d "'" -f 2)
if [ -z "$UPSTREAM" ]
then
echo Could not detect upstream branch >&2
exit 1
fi
# stash any uncommitted changes
git stash | tee "$TEMPFILE"
[ "${PIPESTATUS[0]}" -eq 0 ] || exit 1
# take note if anything was stashed
HAVE_STASH=0
grep -q "No local changes" "$TEMPFILE" || HAVE_STASH=1
# rebase our changes on top of upstream, but keep any merges
git rebase -p "$UPSTREAM"
# restore any stashed changed
[ "$HAVE_STASH" -ne 0 ] && git stash pop -q
fi
exit 0
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment