Skip to contentSkip to conversation

Include a git-push example for creating a remote branch

PATCH In review Shawn O. Pearce 7 participants 9 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Include a git-push example for creating a remote branch

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.

---
 Documentation/git-push.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/git-push.txt +6 -0
index 0dd9caf..7b8e075 100644
@@ -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 <[email protected]>, later rewritten in C
Signature · 1 line
1.5.3.1.840.g0fedbc
#1 lore raw

Documentation/git-push.txt git push origin master:satellite/master:: · line 125

Quoted 6 lines · Shawn O. Pearce
Documentation/git-push.txt +6 -0
+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

#2 lore raw
Quoted 11 lines · Wincent Colaiuta

Documentation/git-push.txt git push origin master:satellite/master:: · line 125

Quoted 6 lines · Shawn O. Pearce
Documentation/git-push.txt +6 -0
+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

#3 lore raw
In reply to Shawn O. Pearce
Quoted 4 lines · Shawn O. Pearce

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

Signature · 1 line
If you can't beat them, arrange to have them beaten.  [George Carlin]
#4 lore raw
Quoted 7 lines · Miles Bader
Quoted 4 lines · Shawn O. Pearce

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

Signature · 1 line
Shawn.
#5 lore raw
Quoted 9 lines · Shawn O. Pearce
Quoted 6 lines · Miles Bader
Quoted 4 lines

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

Signature · 1 line
Do not taunt Happy Fun Ball.
#6 lore raw
Quoted 2 lines · Miles Bader

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
#7 lore raw
Quoted 4 lines · Junio C Hamano

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

#8 lore raw
Quoted 7 lines · Carl Worth
Quoted 4 lines · Junio C Hamano

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.