Skip to content

Instantly share code, notes, and snippets.

@oskarkrawczyk
Forked from pch/git-sync
Last active December 18, 2015 02:39
Show Gist options
  • Save oskarkrawczyk/5712961 to your computer and use it in GitHub Desktop.
Save oskarkrawczyk/5712961 to your computer and use it in GitHub Desktop.
No need to inform about this
#!/bin/bash
SYNC_COLOR_YELLOW="\033[33m"
SYNC_COLOR_GREEN="\033[32m"
SYNC_COLOR_NONE="\033[0m"
git_branch() {
branch=$(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
git_dirty() {
st=$(git status 2>/dev/null | tail -n 1)
if [[ $st == "" ]]
then
dirty="no"
else
if [[ "$st" =~ ^nothing ]]
then
dirty="no"
else
dirty="yes"
fi
fi
}
git_dirty
git_branch
echo -e "\n"
if [[ $dirty == "yes" ]]; then
echo -e "${SYNC_COLOR_YELLOW}Dirty branch, stashing ...${SYNC_COLOR_NONE}"
git stash
fi
echo -e "\n"
echo -e "${SYNC_COLOR_GREEN}Pulling and rebasing $branch ${SYNC_COLOR_NONE}"
if git pull --rebase origin $branch; then
echo -e "\n"
echo -e "${SYNC_COLOR_GREEN}Pushing changes ${SYNC_COLOR_NONE}"
git push origin $branch
fi
if [[ $dirty == "yes" ]]; then
echo -e "\n"
echo -e "${SYNC_COLOR_GREEN}Applying stashed changes${SYNC_COLOR_NONE}"
git stash apply
fi
echo -e "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment