Skip to content

Instantly share code, notes, and snippets.

@agazso
Created November 10, 2010 10:48
Show Gist options
  • Save agazso/670680 to your computer and use it in GitHub Desktop.
Save agazso/670680 to your computer and use it in GitHub Desktop.
Shell script for synchronizing local git repository with remote
#!/bin/sh
PUSH=1
BRANCH=$(git status | head -1 | sed -n 's/^# On branch //p')
STATUS_TAIL=$(git status | tail -1)
if [ "$STATUS_TAIL" = "nothing added to commit but untracked files present (use \"git add\" to track)" ]; then
PUSH=0
fi
if [ "$PUSH" = "1" ]; then
git add -u
if [ $? -ne 0 ]; then exit 1; fi
if [ "$1" = "" ]; then
git commit
else
git commit -m "$1"
fi
if [ $? -ne 0 ]; then
PUSH=0
fi
fi
git pull
if [ $? -ne 0 ]; then exit 1; fi
if [ "$PUSH" = "1" ]; then
if [ "$BRANCH" = "" ]; then
git push
else
git push origin $BRANCH
fi
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment