Skip to content

Instantly share code, notes, and snippets.

@rubic
Created March 16, 2016 13:41
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 rubic/3cc52db64a9d361fa63d to your computer and use it in GitHub Desktop.
Save rubic/3cc52db64a9d361fa63d to your computer and use it in GitHub Desktop.
gitcheck: check status between local and remote repositories
#!/bin/sh
git fetch
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
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