File tree Expand file tree Collapse file tree 5 files changed +304
-0
lines changed
Expand file tree Collapse file tree 5 files changed +304
-0
lines changed Original file line number Diff line number Diff line change 4343 - [ ` git setup ` ] ( #git-setup )
4444 - [ ` git squash ` ] ( #git-squash )
4545 - [ ` git summary ` ] ( #git-summary )
46+ - [ ` git sync ` ] ( #git-sync )
4647 - [ ` git touch ` ] ( #git-touch )
4748 - [ ` git undo ` ] ( #git-undo )
4849 - [ ` git unlock ` ] ( #git-unlock )
@@ -987,3 +988,18 @@ $ git psykorebase master feature
987988` ` `
988989
989990The above rebase ` feature` branch on top of ` master` branch
991+
992+ ## git sync
993+
994+ Sync local branch with its remote branch
995+
996+ ` ` ` bash
997+ $ git sync
998+ ` ` `
999+
1000+ Sync local branch with origin/master
1001+
1002+ ` ` ` bash
1003+ $ git sync origin master
1004+ ` ` `
1005+
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ function _usage()
4+ {
5+ local command=" git sync"
6+ cat << EOS
7+ Usage:
8+ ${command} [<remote> <branch>]
9+ ${command} -h | --help
10+
11+ Sync local branch with <remote>/<branch>.
12+ When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default.
13+ All changes and untracked files and directories will be removed.
14+
15+ Examples:
16+ Sync with upstream of local branch:
17+ ${command}
18+
19+ Sync with origin/master:
20+ ${command} origin master
21+ EOS
22+ }
23+
24+ function main()
25+ {
26+ while [ " $1 " != " " ]; do
27+ case $1 in
28+ -h | --help)
29+ _usage
30+ exit
31+ ;;
32+ * )
33+ if [ " ${remote} " = " " ]; then
34+ local remote=" $1 "
35+ elif [ " ${branch} " = " " ]; then
36+ local branch=" $1 "
37+ else
38+ echo -e " Error: too many arguments.\n"
39+ _usage
40+ exit 1
41+ fi
42+ ;;
43+ esac
44+ shift
45+ done
46+
47+ local remote_branch
48+ if [ " ${remote} " = " " ]; then
49+ if ! remote_branch=" $( git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) " ; then
50+ echo " There is no upstream information of local branch."
51+ exit 1
52+ fi
53+ local branch=" $( git rev-parse --abbrev-ref --symbolic-full-name @) "
54+ local remote=$( git config " branch.${branch} .remote" )
55+ elif [ " ${branch} " = " " ]; then
56+ echo -e " Error: too few arguments.\n"
57+ _usage
58+ exit 1
59+ else
60+ remote_branch=" ${remote} /${branch} "
61+ fi
62+
63+ echo " Are you sure you want to clean all changes & sync with '${remote_branch} '? [y/N]"
64+ local res
65+ read res
66+ case " ${res} " in
67+ " Y" | " y" | " yes" | " Yes" | " YES" )
68+ git fetch " ${remote} " " ${branch} " && git reset --hard " ${remote_branch} " && git clean -d -f -x
69+ ;;
70+ * )
71+ echo " Canceled."
72+ ;;
73+ esac
74+ }
75+
76+ main " $@ "
77+
Original file line number Diff line number Diff line change 1+ .\" generated with Ronn/v0.7.3
2+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3+ .
4+ .TH "GIT\- SYNC" "1" "January 2016" "" ""
5+ .
6+ .SH "NAME"
7+ \fB git \- sync \fR \- Sync local branch with remote branch
8+ .
9+ .SH "SYNOPSIS"
10+ \fB git sync \fR [ <remote> <branch> ]
11+ .
12+ .SH "DESCRIPTION"
13+ Sync local branch with <remote>/<branch>\.
14+ .
15+ .P
16+ When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default\.
17+ .
18+ .P
19+ All changes and untracked files and directories will be removed\.
20+ .
21+ .SH "EXAMPLES"
22+ Sync local branch with its upstream
23+ .
24+ .IP " " 4
25+ .
26+ .nf
27+
28+ $ git sync
29+ .
30+ .fi
31+ .
32+ .IP " " 0
33+ .
34+ .P
35+ Sync local branch with origin/master
36+ .
37+ .IP " " 4
38+ .
39+ .nf
40+
41+ $ git sync origin master
42+ .
43+ .fi
44+ .
45+ .IP " " 0
46+ .
47+ .SH "AUTHOR"
48+ Written by Takuma Yamaguchi <\fI kumon0587@gmail \. com \fR >
49+ .
50+ .SH "REPORTING BUGS"
51+ <\fI https://github \. com/tj/git \- extras/issues \fR >
52+ .
53+ .SH "SEE ALSO"
54+ <\fI https://github \. com/tj/git \- extras \fR >
Original file line number Diff line number Diff line change 1+ git-sync(1) -- Sync local branch with remote branch
2+ =================================================================
3+
4+ ## SYNOPSIS
5+
6+ ` git sync ` [ < ; remote> ; < ; branch> ; ]
7+
8+ ## DESCRIPTION
9+
10+ Sync local branch with < ; remote> ; /< ; branch> ; .
11+
12+ When < ; remote> ; and < ; branch> ; are not specified on the command line, upstream of local branch will be used by default.
13+
14+ All changes and untracked files and directories will be removed.
15+
16+ ## EXAMPLES
17+
18+ Sync local branch with its upstream
19+
20+ $ git sync
21+
22+ Sync local branch with origin/master
23+
24+ $ git sync origin master
25+
26+ ## AUTHOR
27+
28+ Written by Takuma Yamaguchi
< ; < [email protected] > > ; 29+
30+ ## REPORTING BUGS
31+
32+ < ; < https://github.com/tj/git-extras/issues > > ;
33+
34+ ## SEE ALSO
35+
36+ < ; < https://github.com/tj/git-extras > > ;
You can’t perform that action at this time.
0 commit comments