Created
November 27, 2014 16:45
-
-
Save WebPlatformDocs/437f763b948c926ca7ba to your computer and use it in GitHub Desktop.
Check if a pull will be diverged
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
#!/bin/sh | |
# | |
# Source: http://stackoverflow.com/questions/3258243/git-check-if-pull-needed | |
# | |
COUNT=$(git rev-list HEAD...origin/master --count) | |
if [ "$COUNT" -ge "1" ]; then | |
echo 'Must update' | |
git pull | |
echo 'Updated, will send to servers' | |
else | |
echo 'All is fine' | |
fi | |
exit 0 | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u}) | |
BASE=$(git merge-base @ @{u}) | |
COUNT=$(git rev-list HEAD...origin/master --count) | |
if [ $LOCAL = $REMOTE ]; then | |
echo "Up-to-date" | |
elif [ $LOCAL = $BASE ]; then | |
echo "Need to pull" | |
elif [ $REMOTE = $BASE ]; then | |
echo "Need to push" | |
else | |
echo "Diverged" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment