Created
November 10, 2010 10:48
-
-
Save agazso/670680 to your computer and use it in GitHub Desktop.
Shell script for synchronizing local git repository with remote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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