Create a gist now

Instantly share code, notes, and snippets.

Check if a pull will be diverged
#!/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