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

9 messages from 2007-09-06 to 2007-09-06. Participants: Shawn O. Pearce, Miles Bader, Junio C Hamano, Wincent Colaiuta, Kristian Høgsberg, Carl Worth.
Thread: https://gitlist.dev/t/9798

## Shawn O. Pearce, 2007-09-06 04:44

Subject: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <20070906044408.GA588@spearce.org>
URL: https://gitlist.dev/e/20070906044408.GA588%40spearce.org

```
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(-)

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, 2007-09-06 04:54

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <buoodggo0l2.fsf@dhapc248.dev.necel.com>
URL: https://gitlist.dev/e/buoodggo0l2.fsf%40dhapc248.dev.necel.com
In-Reply-To: <20070906044408.GA588@spearce.org>

```
"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, 2007-09-06 05:01

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <20070906050127.GS18160@spearce.org>
URL: https://gitlist.dev/e/20070906050127.GS18160%40spearce.org
In-Reply-To: <buoodggo0l2.fsf@dhapc248.dev.necel.com>

```
Miles Bader <miles.bader@necel.com> wrote:
> "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, 2007-09-06 05:57

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <fc339e4a0709052257m4ddc5784obe64a8b75b79b19@mail.gmail.com>
URL: https://gitlist.dev/e/fc339e4a0709052257m4ddc5784obe64a8b75b79b19%40mail.gmail.com
In-Reply-To: <20070906050127.GS18160@spearce.org>

```
On 9/6/07, Shawn O. Pearce <spearce@spearce.org> wrote:
> 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, 2007-09-06 06:30

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <7v8x7ke260.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v8x7ke260.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <fc339e4a0709052257m4ddc5784obe64a8b75b79b19@mail.gmail.com>

```
"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

```

## Wincent Colaiuta, 2007-09-06 10:50

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <A3C344D0-B2A0-44DC-BCBD-3B2C1EBD24B1@wincent.com>
URL: https://gitlist.dev/e/A3C344D0-B2A0-44DC-BCBD-3B2C1EBD24B1%40wincent.com
In-Reply-To: <20070906044408.GA588@spearce.org>

```
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.

Cheers,
Wincent

```

## Kristian Høgsberg, 2007-09-06 14:57

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <1189090638.3423.0.camel@hinata.boston.redhat.com>
URL: https://gitlist.dev/e/1189090638.3423.0.camel%40hinata.boston.redhat.com
In-Reply-To: <A3C344D0-B2A0-44DC-BCBD-3B2C1EBD24B1@wincent.com>

```
On Thu, 2007-09-06 at 12:50 +0200, Wincent Colaiuta wrote:
> 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

```

## Carl Worth, 2007-09-06 15:48

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <874pi7dcba.wl%cworth@cworth.org>
URL: https://gitlist.dev/e/874pi7dcba.wl%25cworth%40cworth.org
In-Reply-To: <7v8x7ke260.fsf@gitster.siamese.dyndns.org>

```
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, 2007-09-06 17:42

Subject: Re: [PATCH] Include a git-push example for creating a remote branch
Message-ID: <7vps0vadxr.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vps0vadxr.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <874pi7dcba.wl%cworth@cworth.org>

```
Carl Worth <cworth@cworth.org> writes:

> 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.

```
