Skip to content

Instantly share code, notes, and snippets.

@sm-hejazi
Last active April 13, 2024 06:21
Show Gist options
  • Save sm-hejazi/5f49e7197254591d38b14526152eca18 to your computer and use it in GitHub Desktop.
Save sm-hejazi/5f49e7197254591d38b14526152eca18 to your computer and use it in GitHub Desktop.
check git remote
#!/bin/sh
git remote update
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