add git helper and alias for updating another branch

This commit is contained in:
2015-01-27 11:11:09 -07:00
parent e40fed5356
commit 214f5b8a34
2 changed files with 18 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
DEFAULT_REMOTE="upstream"
ROOT_BRANCH="master"
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
@@ -49,6 +50,22 @@ sync_to_remote() {
git fetch ${REMOTE} && git rebase ${REMOTE}/${BRANCH};
}
update_branch() {
BRANCH=$1
: ${BRANCH:=$ROOT_BRANCH}
REMOTE=$2
: ${REMOTE:=$DEFAULT_REMOTE}
echo Updating ${BRANCH} from ${REMOTE}
# check stash stack before and after
old_stash=$(git rev-parse -q --verify refs/stash)
git stash
new_stash=$(git rev-parse -q --verify refs/stash)
# checkout branch and sync to remote, then come back
git checkout ${BRANCH} && git sync ${REMOTE} && git checkout -
# if the stash added to the stack, pop it back off
[ "$old_stash" != "$new_stash" ] && git stash pop
}
get_pr() {
REMOTE=$2
: ${REMOTE:="upstream"}