15 lines
478 B
Bash
Executable file
15 lines
478 B
Bash
Executable file
#!/bin/bash
|
|
|
|
REMOTE="${1:-origin}"
|
|
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 "$REMOTE" && git rebase "$REMOTE/$BRANCH" && ([[ $POP_STASH -eq 1 ]] && git stash pop) || true
|
|
else
|
|
echo "Cannot update in a detached HEAD state"
|
|
fi
|