From 44235defb862b6b805790a973c334db57037be54 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Fri, 14 Nov 2014 14:13:13 -0800 Subject: [PATCH] add a gup command to update a local git branch from its remote origin branch --- zsh/zshrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zsh/zshrc b/zsh/zshrc index e40aaae..85ebd7d 100755 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -233,9 +233,19 @@ if command_exists git; then alias m='git merge' alias s='git status -sb' alias st='git stash' + alias stl='git stash list' alias stp='git stash pop' fi +function gup() { + BRANCH=$(git branch --no-color --list | grep '^\*' | awk '{print $2}') + if [[ "$BRANCH" != "(detached" ]]; then + git stash && git fetch origin && git rebase "origin/$BRANCH" && git stash pop + else + echo "Cannot update in a detached HEAD state" + fi +} + # `cd /path/to/a/file` does `cd /path/to/a` function cd () { if [[ -f "$1" ]]; then