From 12e416a324bb08dfa5c72dee8aa5b4dcfb6ea53e Mon Sep 17 00:00:00 2001 From: Takuma Yamaguchi Date: Thu, 14 Jan 2016 00:19:12 +0900 Subject: [PATCH] add git-sync --- Commands.md | 10 ++++ bin/git-sync | 61 +++++++++++++++++++++++++ man/git-sync.1 | 35 ++++++++++++++ man/git-sync.html | 113 ++++++++++++++++++++++++++++++++++++++++++++++ man/git-sync.md | 30 ++++++++++++ 5 files changed, 249 insertions(+) create mode 100755 bin/git-sync create mode 100644 man/git-sync.1 create mode 100644 man/git-sync.html create mode 100644 man/git-sync.md diff --git a/Commands.md b/Commands.md index a294dbd..ab899f0 100644 --- a/Commands.md +++ b/Commands.md @@ -43,6 +43,7 @@ - [`git setup`](#git-setup) - [`git squash`](#git-squash) - [`git summary`](#git-summary) + - [`git sync`](#git-sync) - [`git touch`](#git-touch) - [`git undo`](#git-undo) - [`git unlock`](#git-unlock) @@ -987,3 +988,12 @@ $ git psykorebase master feature ``` The above rebase `feature` branch on top of `master` branch + +## git sync + +Sync local branch with remote branch + +```bash +$ git sync origin master +``` + diff --git a/bin/git-sync b/bin/git-sync new file mode 100755 index 0000000..765f19a --- /dev/null +++ b/bin/git-sync @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +function _usage() +{ + local command="git sync" + cat << EOS +Usage: + ${command} + ${command} -h | --help | help | ? + +Sync local branch with of . +All changes and untracked files and directories will be removed. + +Example: + ${command} origin master +EOS +} + +function main() +{ + while [ "$1" != "" ]; do + case $1 in + -h | --help | help | "?" ) + _usage + ;; + * ) + if [ "${remote}" = "" ]; then + local remote="$1" + elif [ "${branch}" = "" ]; then + local branch="$1" + else + echo -e "Error: too many arguments.\n" + _usage + exit 1 + fi + ;; + esac + shift + done + + if [ "${remote}" = "" -o "${branch}" = "" ]; then + echo -e "Error: too few arguments.\n" + _usage + exit 1 + fi + + echo "Are you sure you want to clean all changes & sync with '${remote}/${branch}'? [y/N]" + local res + read res + case ${res} in + "Y" | "y" | "yes" | "Yes" | "YES" ) + git fetch '${remote}' && git reset --hard '${remote}'/'${branch}' && git clean -d -f -x + ;; + * ) + echo "Canceled." + ;; + esac +} + +main "$@" + diff --git a/man/git-sync.1 b/man/git-sync.1 new file mode 100644 index 0000000..90a4954 --- /dev/null +++ b/man/git-sync.1 @@ -0,0 +1,35 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-SYNC" "1" "January 2016" "" "" +. +.SH "NAME" +\fBgit\-sync\fR \- Sync local branch with remote branch +. +.SH "SYNOPSIS" +\fBgit sync\fR +. +.SH "DESCRIPTION" +Sync local branch with of \. All changes and untracked files and directories will be removed\. +. +.SH "EXAMPLES" +Sync local branch with origin/master +. +.IP "" 4 +. +.nf + +$ git sync origin master +. +.fi +. +.IP "" 0 +. +.SH "AUTHOR" +Written by Takuma Yamaguchi <\fIkumon0587@gmail\.com\fR> +. +.SH "REPORTING BUGS" +<\fIhttps://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-sync.html b/man/git-sync.html new file mode 100644 index 0000000..05a5c1f --- /dev/null +++ b/man/git-sync.html @@ -0,0 +1,113 @@ + + + + + + git-sync(1) - Sync local branch with remote branch + + + + +
+ + + +
    +
  1. git-sync(1)
  2. +
  3. +
  4. git-sync(1)
  5. +
+ +

NAME

+

+ git-sync - Sync local branch with remote branch +

+ +

SYNOPSIS

+ +

git sync <remote> <branch>

+ +

DESCRIPTION

+ +

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

+ +

EXAMPLES

+ +

Sync local branch with origin/master

+ +
$ git sync origin master
+
+ +

AUTHOR

+ +

Written by Takuma Yamaguchi <kumon0587@gmail.com>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. January 2016
  3. +
  4. git-sync(1)
  5. +
+ +
+ + diff --git a/man/git-sync.md b/man/git-sync.md new file mode 100644 index 0000000..8854634 --- /dev/null +++ b/man/git-sync.md @@ -0,0 +1,30 @@ +git-sync(1) -- Sync local branch with remote branch +================================================================= + +## SYNOPSIS + + `git sync` <remote> <branch> + +## DESCRIPTION + + Sync local branch with <branch> of <remote>. + All changes and untracked files and directories will be removed. + +## EXAMPLES + + Sync local branch with origin/master + + $ git sync origin master + +## AUTHOR + +Written by Takuma Yamaguchi <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> +