Created
October 7, 2016 11:16
-
-
Save yitsushi/5f5a5a9b76c30ada0b70b577b4e292cf to your computer and use it in GitHub Desktop.
fetch remote branch and rebase it. If working directory is dirty than stash them first and apply stash after update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stashq is an alias to prevend auto-sign stashes (prompt for password): | |
# git config --global alias.stashq '-c commit.gpgsign=false stash' | |
function update-from-remote() { | |
remote=${1:-"origin"} | |
branch=${2:-"master"} | |
if ! git remote | grep "${remote}" > /dev/null; then | |
echo "There is no remote like ${remote}" | |
return 1 | |
fi | |
if ! git branch -r | grep "${remote}/${branch}$" > /dev/null; then | |
echo "There is no remote branch like ${remote}/${branch}" | |
return 1 | |
fi | |
dirty=0 | |
[[ $(git diff-index HEAD 2> /dev/null | tail -n1) != "" ]] && dirty=1 | |
if [[ $dirty -eq 1 ]]; then git stashq; fi | |
git fetch "${remote}" ${branch} && git rebase "${remote}/${branch}" | |
if [[ $dirty -eq 1 ]]; then git stashq apply; fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment