Skip to content

Instantly share code, notes, and snippets.

@ruby232
Last active October 16, 2021 12:47
Show Gist options
  • Save ruby232/0cba116321c06cbb347868141bd71c56 to your computer and use it in GitHub Desktop.
Save ruby232/0cba116321c06cbb347868141bd71c56 to your computer and use it in GitHub Desktop.
Pull from git if exists changes
#!/bin/sh
# Take from https://stackoverflow.com/a/3278427/3384529
git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
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