From d2c156ee34726121172ed155a32b97ebb2de4346 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 5 Mar 2015 19:32:30 -0800 Subject: [PATCH] add git-update --- git-update | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 git-update diff --git a/git-update b/git-update new file mode 100755 index 0000000..02cd255 --- /dev/null +++ b/git-update @@ -0,0 +1,14 @@ +#!/bin/sh + +BRANCH=$(git branch --no-color --list | grep '^\*' | awk '{print $2}') +if [[ "$BRANCH" != "(detached" ]]; then + STASH_OUTPUT=$(git stash) + if [[ "$STASH_OUTPUT" = "No local changes to save" ]]; then + POP_STASH=0 + else + POP_STASH=1 + fi + git fetch --prune --tags origin && git rebase "origin/$BRANCH" && ([[ $POP_STASH -eq 1 ]] && git stash pop) || true +else + echo "Cannot update in a detached HEAD state" +fi