git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 6, 2007, 04:44 UTC
Message-ID
<20070906044408.GA588@spearce.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
Next: Miles Bader
Message 1 of 9 in “Include a git-push example for creating a remote branch”
  1. Include a git-push example for creating a remote branchShawn O. Pearce, Sep 6, 2007
  2. Miles BaderSep 6, 2007
  3. Shawn O. PearceSep 6, 2007
  4. Miles BaderSep 6, 2007
  5. Junio C HamanoSep 6, 2007
  6. Carl WorthSep 6, 2007
  7. Junio C HamanoSep 6, 2007
  8. Wincent ColaiutaSep 6, 2007
  9. Kristian HøgsbergSep 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.