-
-
Save oskarkrawczyk/5712961 to your computer and use it in GitHub Desktop.
No need to inform about this
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
#!/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