Last active
August 30, 2021 08:57
-
-
Save pch/5712694 to your computer and use it in GitHub Desktop.
Git sync - light version
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/sh | |
git_branch() { | |
echo $(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 | |
return 1 | |
else | |
if [[ "$st" =~ ^nothing ]] | |
then | |
return 1 | |
else | |
return 0 | |
fi | |
fi | |
} | |
dirty=$(git_dirty) | |
branch=$(git_branch) | |
echo "\n" | |
if $dirty; then | |
echo " Dirty branch, stashing...\n" | |
git stash | |
else | |
echo " Nothing to stash" | |
fi | |
echo "\n" | |
echo " Pulling & rebasing $branch\n" | |
if git pull --rebase origin $branch; then | |
echo " Pushing changes\n" | |
git push origin $branch | |
fi | |
if $dirty; then | |
echo " Applying stashed changes\n" | |
git stash apply | |
fi | |
echo "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment