Skip to content

Instantly share code, notes, and snippets.

@anguyen8
Created May 11, 2015 19:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anguyen8/337791d54c9f3ef1f5e2 to your computer and use it in GitHub Desktop.
Save anguyen8/337791d54c9f3ef1f5e2 to your computer and use it in GitHub Desktop.
GitPush with checking for updates
function gpush () {
# Check if we need to pull before pushing
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
stop=0
if [ $LOCAL = $REMOTE ]; then
echo "Up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "Need to pull. Push aborted."
stop=1
elif [ $REMOTE = $BASE ]; then
echo "Need to push"
else
echo "Diverged"
fi
# Pushing
if [ $stop -eq 0 ]; then
git push
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment