Skip to content

Instantly share code, notes, and snippets.

@WebPlatformDocs
Created November 27, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebPlatformDocs/437f763b948c926ca7ba to your computer and use it in GitHub Desktop.
Save WebPlatformDocs/437f763b948c926ca7ba to your computer and use it in GitHub Desktop.
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