add a gup command to update a local git branch from its remote origin branch

This commit is contained in:
Sami Samhuri 2014-11-14 14:13:13 -08:00
parent cad264db25
commit 44235defb8

View file

@ -233,9 +233,19 @@ if command_exists git; then
alias m='git merge' alias m='git merge'
alias s='git status -sb' alias s='git status -sb'
alias st='git stash' alias st='git stash'
alias stl='git stash list'
alias stp='git stash pop' alias stp='git stash pop'
fi 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` # `cd /path/to/a/file` does `cd /path/to/a`
function cd () { function cd () {
if [[ -f "$1" ]]; then if [[ -f "$1" ]]; then