Created
May 11, 2015 19:20
-
-
Save anguyen8/337791d54c9f3ef1f5e2 to your computer and use it in GitHub Desktop.
GitPush with checking for updates
This file contains 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
function gpush () { | |
# Check if we need to pull before pushing | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u}) | |
BASE=$(git merge-base @ @{u}) | |
stop=0 | |
if [ $LOCAL = $REMOTE ]; then | |
echo "Up-to-date" | |
elif [ $LOCAL = $BASE ]; then | |
echo "Need to pull. Push aborted." | |
stop=1 | |
elif [ $REMOTE = $BASE ]; then | |
echo "Need to push" | |
else | |
echo "Diverged" | |
fi | |
# Pushing | |
if [ $stop -eq 0 ]; then | |
git push | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment