From 214f5b8a34e9412b5b0c685d655bca6c8b962fb4 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 27 Jan 2015 11:11:09 -0700 Subject: [PATCH] add git helper and alias for updating another branch --- git/gitconfig | 1 + git/githelpers | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/git/gitconfig b/git/gitconfig index 496df31..699d56c 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -30,6 +30,7 @@ l = "!source ~/.githelpers && pretty_git_log" la = !git l --all sync = "!source ~/.githelpers && sync_to_remote" + bsync = "!source ~/.githelpers && update_branch" todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *' pr = "!source ~/.githelpers && get_pr" diff --git a/git/githelpers b/git/githelpers index 5906a99..dc1a78e 100644 --- a/git/githelpers +++ b/git/githelpers @@ -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"}