threads / patch / 9798

patchInclude a git-push example for creating a remote branch

Subject: [PATCH] Include a git-push example for creating a remote branch

## tl;dr

9 messages between Sep 6, 2007 and Sep 6, 2007. Diffs are folded; open one to read it.

replies: 8people: 7as markdown or json

Shawn O. Pearce· Sep 6, 2007, 04:44 UTC · lore

Many users get confused when `git push origin master:foo` works when foo already exists on the remote repository but are confused when foo doesn't exist as a branch and this form does not create the branch foo.

This new example highlights the trick of including refs/heads/ in front of the desired branch name to create a branch.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 Documentation/git-push.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Show changes to Documentation/git-push.txt +6 −0
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 0dd9caf..7b8e075 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -117,6 +117,12 @@ git push origin master:satellite/master::
 	the ref that matches `satellite/master` (most likely, it would
 	be `refs/remotes/satellite/master`) in `origin` repository with it.
 
+git push origin master:refs/heads/experimental::
+	Create the branch `experimental` in the `origin` repository
+	by copying the current `master` branch.  This form is usually
+	needed to create a new branch in the remote repository as
+	there is no `experimental` branch to match.
+
 Author
 ------
 Written by Junio C Hamano <junkio@cox.net>, later rewritten in C
-- 
1.5.3.1.840.g0fedbc
Miles Bader· Sep 6, 2007, 04:54 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Include a git-push example for creating a remote branch

"Shawn O. Pearce" <spearce@spearce.org> writes:
> Many users get confused when `git push origin master:foo` works
> when foo already exists on the remote repository but are confused
> when foo doesn't exist as a branch and this form does not create
> the branch foo.
Hmm, what _does_ it do in that case...?
-Miles
-- 
If you can't beat them, arrange to have them beaten.  [George Carlin]
Shawn O. Pearce· Sep 6, 2007, 05:01 UTC · re: Miles Bader · lore

Re: [PATCH] Include a git-push example for creating a remote branch

Miles Bader <miles.bader@necel.com> wrote:
Show 7 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> > Many users get confused when `git push origin master:foo` works
> > when foo already exists on the remote repository but are confused
> > when foo doesn't exist as a branch and this form does not create
> > the branch foo.
> 
> Hmm, what _does_ it do in that case...?
error: dst refspec experimental does not match any existing ref on the remote and does not start with refs/.
-- 
Shawn.
Miles Bader· Sep 6, 2007, 05:57 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Include a git-push example for creating a remote branch

On 9/6/07, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 9 quoted lines
> Miles Bader <miles.bader@necel.com> wrote:
> > > Many users get confused when `git push origin master:foo` works
> > > when foo already exists on the remote repository but are confused
> > > when foo doesn't exist as a branch and this form does not create
> > > the branch foo.
> >
> > Hmm, what _does_ it do in that case...?
>
> error: dst refspec experimental does not match any existing ref on the remote and does not start with refs/.

Hmm, I'm assuming people don't want to default to just creating a new remote ref ('cause it might be too easy to muck up a remote archive that way), but it seems like it would be nice to have a "prettier" way to create a remote ref than explicitly giving the whole ref path on the remote side.

Maybe I"m weird, but I tend to think of the refs/... syntax as being for "only if you're doing something funny" cases.

I'm thinking of something like:
  ... create new local branch "zoink" ...
  git push --create origin zoink
-Miles
-- 
Do not taunt Happy Fun Ball.
Junio C Hamano· Sep 6, 2007, 06:30 UTC · re: Miles Bader · lore

Re: [PATCH] Include a git-push example for creating a remote branch

"Miles Bader" <miles@gnu.org> writes:
> Maybe I"m weird, but I tend to think of the refs/... syntax as being
> for "only if you're doing something funny" cases.

The "refs/" syntax is there as the lowest level that is universally usable to create and any ref. It can be used to push to branches, tags, or even remotes (aka "simulated fetch in reverse").

It is just nobody felt strong enough reason to sugarcoat the normalized syntax with something like:

	git push --create remote foo v1.2.0

You can be a hero by updating git-push to take such, and make it interpret as if the user passed the normalized syntax which is:

	git push remote foo:refs/heads/foo v1.2.0:refs/tags/v1.2.0
Carl Worth· Sep 6, 2007, 15:48 UTC · re: Junio C Hamano · lore

Re: [PATCH] Include a git-push example for creating a remote branch

On Wed, 05 Sep 2007 23:30:31 -0700, Junio C Hamano wrote:
> It is just nobody felt strong enough reason to sugarcoat the
> normalized syntax with something like:
>
> 	git push --create remote foo v1.2.0
Couldn't we just use an initial + to indicate this as well?
I would imagine an exchange like this:
    $ git push remote foo
    git: No branch 'foo' exists in the remote server, to create it use:
	git push remote +foo

But regardless of the syntax, it would be nice if the error message were explicit about how to achieve the goal the user wants. It's just that forcing the user to say "foo:refs/heads/foo" seems a way to force the user to get plumbing grime on their clean hands.

-Carl
Junio C Hamano· Sep 6, 2007, 17:42 UTC · re: Carl Worth · lore

Re: [PATCH] Include a git-push example for creating a remote branch

Carl Worth <cworth@cworth.org> writes:
Show 7 quoted lines
> On Wed, 05 Sep 2007 23:30:31 -0700, Junio C Hamano wrote:
>> It is just nobody felt strong enough reason to sugarcoat the
>> normalized syntax with something like:
>>
>> 	git push --create remote foo v1.2.0
>
> Couldn't we just use an initial + to indicate this as well?

Unfortunately, no, because + has already been taken to mean something completely different.

Wincent Colaiuta· Sep 6, 2007, 10:50 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Include a git-push example for creating a remote branch

El 6/9/2007, a las 6:44, Shawn O. Pearce escribió:
Show 6 quoted lines
> +git push origin master:refs/heads/experimental::
> +	Create the branch `experimental` in the `origin` repository
> +	by copying the current `master` branch.  This form is usually
> +	needed to create a new branch in the remote repository as
> +	there is no `experimental` branch to match.
> +

A welcome addition; I was puzzled the first time I tried this myself too.

Cheers, Wincent

Kristian Høgsberg· Sep 6, 2007, 14:57 UTC · re: Wincent Colaiuta · lore

Re: [PATCH] Include a git-push example for creating a remote branch

On Thu, 2007-09-06 at 12:50 +0200, Wincent Colaiuta wrote:
Show 11 quoted lines
> El 6/9/2007, a las 6:44, Shawn O. Pearce escribió:
> 
> > +git push origin master:refs/heads/experimental::
> > +	Create the branch `experimental` in the `origin` repository
> > +	by copying the current `master` branch.  This form is usually
> > +	needed to create a new branch in the remote repository as
> > +	there is no `experimental` branch to match.
> > +
> 
> A welcome addition; I was puzzled the first time I tried this myself  
> too.

Indeed, but a even better approach might be to expand the error message with a sugestion on how to create a branch.

Kristian

← back to recent threads