diff --git a/bin/git-sync b/bin/git-sync index 765f19a..cbb6845 100755 --- a/bin/git-sync +++ b/bin/git-sync @@ -5,14 +5,19 @@ function _usage() local command="git sync" cat << EOS Usage: - ${command} - ${command} -h | --help | help | ? + ${command} [ ] + ${command} -h | --help -Sync local branch with of . +Sync local branch with /. +When and are not specified on the command line, upstream of local branch will be used by default. All changes and untracked files and directories will be removed. -Example: - ${command} origin master +Examples: + Sync with upstream of local branch: + ${command} + + Sync with origin/master: + ${command} origin master EOS } @@ -20,8 +25,9 @@ function main() { while [ "$1" != "" ]; do case $1 in - -h | --help | help | "?" ) + -h | --help) _usage + exit ;; * ) if [ "${remote}" = "" ]; then @@ -38,18 +44,24 @@ function main() shift done - if [ "${remote}" = "" -o "${branch}" = "" ]; then - echo -e "Error: too few arguments.\n" - _usage - exit 1 + if [ "${remote}" = "" ]; then + local remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})" + branch="$(git rev-parse --abbrev-ref --symbolic-full-name @)" + remote="${remote_branch%%/${branch}}" + elif [ "${branch}" = "" ]; then + echo -e "Error: too few arguments.\n" + _usage + exit 1 + else + local remote_branch="${remote}/${branch}" fi - echo "Are you sure you want to clean all changes & sync with '${remote}/${branch}'? [y/N]" + echo "Are you sure you want to clean all changes & sync with '${remote_branch}'? [y/N]" local res read res - case ${res} in + case "${res}" in "Y" | "y" | "yes" | "Yes" | "YES" ) - git fetch '${remote}' && git reset --hard '${remote}'/'${branch}' && git clean -d -f -x + echo "git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}" && git clean -d -f -x" ;; * ) echo "Canceled." diff --git a/man/git-sync.1 b/man/git-sync.1 index 90a4954..498b2f2 100644 --- a/man/git-sync.1 +++ b/man/git-sync.1 @@ -7,12 +7,31 @@ \fBgit\-sync\fR \- Sync local branch with remote branch . .SH "SYNOPSIS" -\fBgit sync\fR +\fBgit sync\fR [ ] . .SH "DESCRIPTION" -Sync local branch with of \. All changes and untracked files and directories will be removed\. +Sync local branch with /\. +. +.P +When and are not specified on the command line, upstream of local branch will be used by default\. +. +.P +All changes and untracked files and directories will be removed\. . .SH "EXAMPLES" +Sync local branch with its upstream +. +.IP "" 4 +. +.nf + +$ git sync +. +.fi +. +.IP "" 0 +. +.P Sync local branch with origin/master . .IP "" 4 diff --git a/man/git-sync.html b/man/git-sync.html index 05a5c1f..234cdb0 100644 --- a/man/git-sync.html +++ b/man/git-sync.html @@ -75,15 +75,23 @@

SYNOPSIS

-

git sync <remote> <branch>

+

git sync [ <remote> <branch> ]

DESCRIPTION

-

Sync local branch with <branch> of <remote>. - All changes and untracked files and directories will be removed.

+

Sync local branch with <remote>/<branch>.

+ +

When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default.

+ +

All changes and untracked files and directories will be removed.

EXAMPLES

+

Sync local branch with its upstream

+ +
$ git sync
+
+

Sync local branch with origin/master

$ git sync origin master
@@ -91,7 +99,7 @@
 
 

AUTHOR

-

Written by Takuma Yamaguchi <kumon0587@gmail.com>

+

Written by Takuma Yamaguchi <kumon0587@gmail.com>

REPORTING BUGS

diff --git a/man/git-sync.md b/man/git-sync.md index 8854634..f2f6e43 100644 --- a/man/git-sync.md +++ b/man/git-sync.md @@ -3,15 +3,22 @@ git-sync(1) -- Sync local branch with remote branch ## SYNOPSIS - `git sync` <remote> <branch> + `git sync` [ <remote> <branch> ] ## DESCRIPTION - Sync local branch with <branch> of <remote>. + Sync local branch with <remote>/<branch>. + + When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default. + All changes and untracked files and directories will be removed. ## EXAMPLES + Sync local branch with its upstream + + $ git sync + Sync local branch with origin/master $ git sync origin master @@ -27,4 +34,3 @@ Written by Takuma Yamaguchi <> ## SEE ALSO <> -