-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-sync
executable file
·59 lines (51 loc) · 1.02 KB
/
git-sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash -e
case `uname` in
Linux|CYGWIN*) ECHO="echo -e" ;;
*) ECHO="echo" ;;
esac
usage() {
$ECHO "git sync [options] <remote>"
$ECHO
$ECHO "Options:"
$ECHO "-s, --stash \tstash any uncommitted changes before syncing"
$ECHO "-p, --pop \tpop stashed changes after syncing"
$ECHO "-a, --apply \tapply stashed changes after syncing"
exit 1
}
AFTER=""
while [ $# -gt 0 ]; do
case $1 in
-s|--stash)
STASH=true
shift
;;
-p|--pop)
AFTER=pop
shift
;;
-a|--apply)
AFTER=apply
shift
;;
-*)
$ECHO "Unknown option $1" ; exit 1 ;;
*)
if [ ! X$REMOTE = X ]; then
$ECHO "Unexpected extra argument $1" ; exit 1
fi
REMOTE=$1
shift
;;
esac
done
if [ "$REMOTE" == "" ]; then
usage
fi
if [ "$STASH" == "true" ]; then
git stash
fi
git fetch ${REMOTE}
git reset --hard ${REMOTE}/$(git rev-parse --abbrev-ref HEAD)
if [ "$STASH" == "true" ] && [ -n "$AFTER" ]; then
git stash $AFTER
fi