mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
implements remote pref for create-branch
This commit is contained in:
parent
820b7cd41b
commit
7d3ab83ec3
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
test $# -eq 0 && echo "branch argument required." 1>&2 && exit 1
|
||||
|
||||
# preference takes lowest priority; look for remote from prefs first
|
||||
REMOTE_PREF=`git config git-extras.create-branch.remote`
|
||||
if [ ${REMOTE_PREF} == "true" ]; then
|
||||
REMOTE=origin
|
||||
elif [ "$REMOTE_PREF" != ""]; then
|
||||
if [ -n "$REMOTE_PREF" ]; then
|
||||
REMOTE=$REMOTE_PREF
|
||||
fi
|
||||
|
||||
|
|
@ -26,17 +26,22 @@ do
|
|||
shift
|
||||
done
|
||||
|
||||
# handle ambiguous `-r` option argument by shift
|
||||
if [[ -z $BRANCH ]] && [[ -n $REMOTE ]]
|
||||
then
|
||||
BRANCH=$REMOTE
|
||||
REMOTE=origin
|
||||
fi
|
||||
|
||||
test -z $BRANCH && echo "branch required." 1>&2 && exit 1
|
||||
test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
|
||||
|
||||
if [[ -n $REMOTE ]]
|
||||
then
|
||||
git ls-remote --exit-code $REMOTE 1>/dev/null 2>/tmp/ls-remote-error
|
||||
if [ $? = 0 ]
|
||||
REMOTE_EXIT=$?
|
||||
REMOTE_ERROR=$(</tmp/ls-remote-error)
|
||||
rm -f /tmp/ls-remote-error
|
||||
if [ $REMOTE_EXIT -eq 0 ]
|
||||
then
|
||||
git push $REMOTE HEAD:refs/heads/$BRANCH
|
||||
git fetch $REMOTE
|
||||
|
|
@ -44,8 +49,9 @@ then
|
|||
exit $?
|
||||
else
|
||||
echo
|
||||
echo " Error connecting to remote '$REMOTE': `cat /tmp/ls-remote-error`"
|
||||
rm -f /tmp/ls-remote-error
|
||||
echo " Error connecting to remote '$REMOTE': $REMOTE_ERROR"
|
||||
echo
|
||||
exit $REMOTE_EXIT
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "GIT\-CREATE\-BRANCH" "1" "October 2017" "" "Git Extras"
|
||||
.TH "GIT\-CREATE\-BRANCH" "1" "June 2019" "" "Git Extras"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBgit\-create\-branch\fR \- Create branches
|
||||
|
|
@ -24,26 +24,76 @@ Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is
|
|||
.P
|
||||
The name of the branch to create\.
|
||||
.
|
||||
.SH "EXAMPLES"
|
||||
.SH "PREFERENCES"
|
||||
You may save your default preference for the \fBremote\fR option above by using \fBgit config\fR with the key \fBgit\-extras\.create\-branch\.remote\fR whose value will be the default remote when \fB[\-r|\-\-remote]\fR is not specified\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git config git\-extras\.create\-branch\.remote lucinda
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
The command line option \fB\-r|\-\-remote\fR will override this preference\.
|
||||
.
|
||||
.SH "EXAMPLES"
|
||||
With no remote preference set:
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
# creates local branch \'integration\'
|
||||
$ git create\-branch integration
|
||||
|
||||
# creates local & remote branch \'integration\' (on default \'origin\')
|
||||
$ git create\-branch \-r integration
|
||||
|
||||
# creates local & remote branch \'integration\' on \'upstream\'
|
||||
$ git create\-branch \-r upstream integration
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
With \fBgit\-extras\.create\-branch\.remote\fR preference set to \'lucinda\':
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
# creates local & remote branch \'integration\' (on preference \'lucinda\')
|
||||
$ git create\-branch integration
|
||||
|
||||
# overriding preference, using default `\-r` of \'origin\'
|
||||
# creates local & remote branch \'integration\' on default \'origin\'
|
||||
$ git create\-branch \-r integration
|
||||
|
||||
# overriding preference, using specified `\-r` of \'upstream\'
|
||||
# creates local & remote branch \'integration\' on \'upstream\'
|
||||
$ git create\-branch \-r upstream integration
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SH "NOTES"
|
||||
As of 4\.4\.0, the default behavior has changed\. \fBgit\-create\-branch\fR will no longer automatically setup a remote tracking branch unless the \fB\-r|\-remote\fR option is specified\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
As of 4\.4\.0, the default behavior has changed\. \fBgit\-create\-branch\fR will no longer automatically setup a remote tracking branch unless the \fB\-r|\-remote\fR option is specified\. See additional note on preference feature in 4\.8\.0\-dev below\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
As of 4\.8\.0\-dev, the \fBremote\fR option can be set via \fBgit config\fR preference as described in \fIPreferences\fR section\.
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SH "AUTHOR"
|
||||
Written by Jonhnny Weslley <\fIjw@jonhnnyweslley\.net\fR>
|
||||
.
|
||||
.br
|
||||
Modified by Mark Pitman <\fImark\.pitman@gmail\.com\fR>
|
||||
Written by Jonhnny Weslley <\fIjw@jonhnnyweslley\.net\fR> Modified by Mark Pitman <\fImark\.pitman@gmail\.com\fR>, Brian Murrell <\fIbtmurrell@gmail\.com\fR>\.
|
||||
.
|
||||
.SH "REPORTING BUGS"
|
||||
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
<a href="#SYNOPSIS">SYNOPSIS</a>
|
||||
<a href="#DESCRIPTION">DESCRIPTION</a>
|
||||
<a href="#OPTIONS">OPTIONS</a>
|
||||
<a href="#PREFERENCES">PREFERENCES</a>
|
||||
<a href="#EXAMPLES">EXAMPLES</a>
|
||||
<a href="#NOTES">NOTES</a>
|
||||
<a href="#AUTHOR">AUTHOR</a>
|
||||
|
|
@ -81,35 +82,67 @@
|
|||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
<p> Creates local branch named <branchname> and optionally sets up a remote tracking branch.</p>
|
||||
<p>Creates local branch named <branchname> and optionally sets up a remote tracking branch.</p>
|
||||
|
||||
<h2 id="OPTIONS">OPTIONS</h2>
|
||||
|
||||
<p> <-r|--remote [remote_name]></p>
|
||||
<p><-r|--remote [remote_name]></p>
|
||||
|
||||
<p> Setup a remote tracking branch using <code>remote_name</code>. If <code>remote_name</code> is not supplied, use <code>origin</code> by default.</p>
|
||||
<p>Setup a remote tracking branch using <code>remote_name</code>. If <code>remote_name</code> is not supplied, use <code>origin</code> by default.</p>
|
||||
|
||||
<p> <branchname></p>
|
||||
<p><branchname></p>
|
||||
|
||||
<p> The name of the branch to create.</p>
|
||||
<p>The name of the branch to create.</p>
|
||||
|
||||
<h2 id="PREFERENCES">PREFERENCES</h2>
|
||||
|
||||
<p>You may save your default preference for the <code>remote</code> option above by using <code>git config</code> with the key <code>git-extras.create-branch.remote</code> whose value will be the default remote when <code>[-r|--remote]</code> is not specified.</p>
|
||||
|
||||
<pre><code>$ git config git-extras.create-branch.remote lucinda
|
||||
</code></pre>
|
||||
|
||||
<p>The command line option <code>-r|--remote</code> will override this preference.</p>
|
||||
|
||||
<h2 id="EXAMPLES">EXAMPLES</h2>
|
||||
|
||||
<pre><code>$ git create-branch integration
|
||||
<p>With no remote preference set:</p>
|
||||
|
||||
<pre><code># creates local branch 'integration'
|
||||
$ git create-branch integration
|
||||
|
||||
# creates local & remote branch 'integration' (on default 'origin')
|
||||
$ git create-branch -r integration
|
||||
|
||||
# creates local & remote branch 'integration' on 'upstream'
|
||||
$ git create-branch -r upstream integration
|
||||
</code></pre>
|
||||
|
||||
<p>With <code>git-extras.create-branch.remote</code> preference set to 'lucinda':</p>
|
||||
|
||||
<pre><code># creates local & remote branch 'integration' (on preference 'lucinda')
|
||||
$ git create-branch integration
|
||||
|
||||
# overriding preference, using default `-r` of 'origin'
|
||||
# creates local & remote branch 'integration' on default 'origin'
|
||||
$ git create-branch -r integration
|
||||
|
||||
# overriding preference, using specified `-r` of 'upstream'
|
||||
# creates local & remote branch 'integration' on 'upstream'
|
||||
$ git create-branch -r upstream integration
|
||||
</code></pre>
|
||||
|
||||
<h2 id="NOTES">NOTES</h2>
|
||||
|
||||
<p>As of 4.4.0, the default behavior has changed. <code>git-create-branch</code> will no longer automatically setup a remote tracking branch unless the <code>-r|-remote</code> option is specified.</p>
|
||||
<ul>
|
||||
<li><p>As of 4.4.0, the default behavior has changed. <code>git-create-branch</code> will no longer automatically setup a remote tracking branch unless the <code>-r|-remote</code> option is specified. See additional note on preference feature in 4.8.0-dev below.</p></li>
|
||||
<li><p>As of 4.8.0-dev, the <code>remote</code> option can be set via <code>git config</code> preference as described in <a href="#PREFERENCES" data-bare-link="true">Preferences</a> section.</p></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Jonhnny Weslley <<a href="mailto:jw@jonhnnyweslley.net" data-bare-link="true">jw@jonhnnyweslley.net</a>><br />
|
||||
Modified by Mark Pitman <<a href="mailto:mark.pitman@gmail.com" data-bare-link="true">mark.pitman@gmail.com</a>></p>
|
||||
<p>Written by Jonhnny Weslley <<a href="mailto:jw@jonhnnyweslley.net" data-bare-link="true">jw@jonhnnyweslley.net</a>>
|
||||
Modified by Mark Pitman <<a href="mailto:mark.pitman@gmail.com" data-bare-link="true">mark.pitman@gmail.com</a>>, Brian Murrell <<a href="mailto:btmurrell@gmail.com" data-bare-link="true">btmurrell@gmail.com</a>>.</p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
@ -122,7 +155,7 @@ Modified by Mark Pitman <<a href="mailto:&#
|
|||
|
||||
<ol class='man-decor man-foot man foot'>
|
||||
<li class='tl'></li>
|
||||
<li class='tc'>October 2017</li>
|
||||
<li class='tc'>June 2019</li>
|
||||
<li class='tr'>git-create-branch(1)</li>
|
||||
</ol>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,33 +7,62 @@ git-create-branch(1) -- Create branches
|
|||
|
||||
## DESCRIPTION
|
||||
|
||||
Creates local branch named <branchname> and optionally sets up a remote tracking branch.
|
||||
Creates local branch named <branchname> and optionally sets up a remote tracking branch.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
<-r|--remote [remote_name]>
|
||||
<-r|--remote [remote_name]>
|
||||
|
||||
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
|
||||
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
|
||||
|
||||
<branchname>
|
||||
<branchname>
|
||||
|
||||
The name of the branch to create.
|
||||
The name of the branch to create.
|
||||
|
||||
## PREFERENCES
|
||||
|
||||
You may save your default preference for the `remote` option above by using `git config` with the key `git-extras.create-branch.remote` whose value will be the default remote when `[-r|--remote]` is not specified.
|
||||
|
||||
$ git config git-extras.create-branch.remote lucinda
|
||||
|
||||
The command line option `-r|--remote` will override this preference.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
With no remote preference set:
|
||||
|
||||
# creates local branch 'integration'
|
||||
$ git create-branch integration
|
||||
|
||||
# creates local & remote branch 'integration' (on default 'origin')
|
||||
$ git create-branch -r integration
|
||||
|
||||
# creates local & remote branch 'integration' on 'upstream'
|
||||
$ git create-branch -r upstream integration
|
||||
|
||||
With `git-extras.create-branch.remote` preference set to 'lucinda':
|
||||
|
||||
# creates local & remote branch 'integration' (on preference 'lucinda')
|
||||
$ git create-branch integration
|
||||
|
||||
# overriding preference, using default `-r` of 'origin'
|
||||
# creates local & remote branch 'integration' on default 'origin'
|
||||
$ git create-branch -r integration
|
||||
|
||||
# overriding preference, using specified `-r` of 'upstream'
|
||||
# creates local & remote branch 'integration' on 'upstream'
|
||||
$ git create-branch -r upstream integration
|
||||
|
||||
## NOTES
|
||||
|
||||
As of 4.4.0, the default behavior has changed. `git-create-branch` will no longer automatically setup a remote tracking branch unless the `-r|-remote` option is specified.
|
||||
* As of 4.4.0, the default behavior has changed. `git-create-branch` will no longer automatically setup a remote tracking branch unless the `-r|-remote` option is specified. See additional note on preference feature in 4.8.0-dev below.
|
||||
|
||||
* As of 4.8.0-dev, the `remote` option can be set via `git config` preference as described in [Preferences](#PREFERENCES) section.
|
||||
|
||||
## AUTHOR
|
||||
|
||||
Written by Jonhnny Weslley <<jw@jonhnnyweslley.net>>
|
||||
Modified by Mark Pitman <<mark.pitman@gmail.com>>
|
||||
Written by Jonhnny Weslley <<jw@jonhnnyweslley.net>>
|
||||
Modified by Mark Pitman <<mark.pitman@gmail.com>>, Brian Murrell <<btmurrell@gmail.com>>.
|
||||
|
||||
## REPORTING BUGS
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ git-extras(1) -- Awesome GIT utilities
|
|||
- **git-refactor(1)** Create refactor branch
|
||||
- **git-release(1)** Commit, tag and push changes to the repository
|
||||
- **git-rename-branch(1)** rename local branch and push to remote
|
||||
- **git-rename-remote(1)** Rename a remote
|
||||
- **git-rename-tag(1)** Rename a tag
|
||||
- **git-repl(1)** git read-eval-print-loop
|
||||
- **git-reset-file(1)** Reset one file
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ git-rebase-patch(1) git-rebase-patch
|
|||
git-refactor(1) git-refactor
|
||||
git-release(1) git-release
|
||||
git-rename-branch(1) git-rename-branch
|
||||
git-rename-remote(1) git-rename-remote
|
||||
git-rename-tag(1) git-rename-tag
|
||||
git-repl(1) git-repl
|
||||
git-reset-file(1) git-reset-file
|
||||
|
|
|
|||
Loading…
Reference in a new issue