add git helper and alias for updating another branch
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user