mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 15:36:21 -04:00
upstream is used by default
This commit is contained in:
parent
12e416a324
commit
3481ff245e
38
bin/git-sync
38
bin/git-sync
|
|
@ -5,14 +5,19 @@ function _usage()
|
|||
local command="git sync"
|
||||
cat << EOS
|
||||
Usage:
|
||||
${command} <remote> <branch>
|
||||
${command} -h | --help | help | ?
|
||||
${command} [<remote> <branch>]
|
||||
${command} -h | --help
|
||||
|
||||
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.
|
||||
|
||||
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."
|
||||
|
|
|
|||
|
|
@ -7,12 +7,31 @@
|
|||
\fBgit\-sync\fR \- Sync local branch with remote branch
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
\fBgit sync\fR <remote> <branch>
|
||||
\fBgit sync\fR [ <remote> <branch> ]
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Sync local branch with <branch> of <remote>\. All changes and untracked files and directories will be removed\.
|
||||
Sync local branch with <remote>/<branch>\.
|
||||
.
|
||||
.P
|
||||
When <remote> and <branch> 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
|
||||
|
|
|
|||
|
|
@ -75,15 +75,23 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p> <code>git sync</code> <remote> <branch></p>
|
||||
<p> <code>git sync</code> [ <remote> <branch> ]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
<p> Sync local branch with <branch> of <remote>.
|
||||
All changes and untracked files and directories will be removed.</p>
|
||||
<p> Sync local branch with <remote>/<branch>.</p>
|
||||
|
||||
<p> When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default.</p>
|
||||
|
||||
<p> All changes and untracked files and directories will be removed.</p>
|
||||
|
||||
<h2 id="EXAMPLES">EXAMPLES</h2>
|
||||
|
||||
<p> Sync local branch with its upstream</p>
|
||||
|
||||
<pre><code>$ git sync
|
||||
</code></pre>
|
||||
|
||||
<p> Sync local branch with origin/master</p>
|
||||
|
||||
<pre><code>$ git sync origin master
|
||||
|
|
@ -91,7 +99,7 @@
|
|||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Takuma Yamaguchi <<a href="mailto:kumon0587@gmail.com" data-bare-link="true">kumon0587@gmail.com</a>></p>
|
||||
<p>Written by Takuma Yamaguchi <<a href="mailto:kumon0587@gmail.com" data-bare-link="true">kumon0587@gmail.com</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <<kumon0587@gmail.com>>
|
|||
## SEE ALSO
|
||||
|
||||
<<https://github.com/tj/git-extras>>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue