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

Re: [PATCH v3] git checkout: create unparented branch by --orphan

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2010, 20:19 UTC
Message-ID
<7vljdk85z4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<3F619EAA-288D-4310-B9C6-8121FE00E7B0@pobox.com>
Chris Johnsen <chris_johnsen@pobox.com> writes:
Show 8 quoted lines
> --orphan::
> 	Create a new, 'orphan' branch named <new_branch>, and start it
> 	at <start_point>. The first commit made on this new branch will
> 	have no parents (it will be the root of a new history that is
> 	not connected to any the other branches or commits).
> +
> An orphan branch allows you to start a new history that records a set of
> paths similar to <start_point>.

Strictly speaking, an orphan branch allows you to start a new history that does not have any existing commit as its ancestry, and that is all there to it. While the "mostly common paths" aspect is worth mentioning, as it is the use case it primarily targets, it is still secondary to the description of "what it does." "What it is used for" should come after the reader is told "what it does."

It would probably be better to say that the index and the working tree is kept intact during --orphan process as part of "what it does", before talking about "mostly common paths":

	Create a new branch <new_branch> and switch to it.  The first
	commit you will make on this branch will become the root of a new
	history, disconnected from any of existing commits.  
	The index and the working tree is adjusted as if you ran "git
	checkout <start_point>" (without -b nor paths), to allow you to
	easily record the root commit of the new history that records a
	set of paths similar to <start_point>.
Show 7 quoted lines
> This can be useful when you want to publish the tree from a commit
> without
> exposing its full history.
> You might want to do this to publish an open source branch of a project
> whose current tree is "clean", but whose full history contains
> proprietary
> or otherwise encumbered bits of code.
Good.
Show 7 quoted lines
> +
> If you want to start a disconnected history that records a set of paths
> that is totally different from <start_point>, you may want to clear the
> index and the working tree after creating the orphan branch.
> Run `git rm -rf .` from the top level of the working tree, then prepare
> your new files by copying them from elsewhere, extracting a tarball, or
> otherwise populating the working tree.
Good, even though I am tempted to suggest rephrasing it further:
        If you want to start a disconnected history that records a set of
        paths that is totally different from <start_point>, you could
        clear the index and the working tree after creating the orphan
        branch by running `git rm -rf .` from the top level of the working
        tree.  Then prepare your new files by copying them from elsewhere,
        extracting a tarball, or otherwise populating the working tree.
	In general, however, it is cleaner and easier to create such an
        unrelated history in a separate repository than creating in the
        same repository.
Previous: Jakub Narebski
Message 13 of 13 in “git checkout: create unparented branch by --orphan”
  1. git checkout: create unparented branch by --orphanErick Mattos, Mar 21, 2010
  2. Peter BaumannMar 21, 2010
  3. Erick MattosMar 21, 2010
  4. Junio C HamanoMar 21, 2010
  5. Erick MattosMar 21, 2010
  6. Michael J GruberMar 22, 2010
  7. Chris JohnsenMar 22, 2010
  8. Erick MattosMar 22, 2010
  9. Junio C HamanoMar 21, 2010
  10. Chris JohnsenMar 22, 2010
  11. Erick MattosMar 22, 2010
  12. Translating error messages in Git (was: Re: [PATCH v3] git checkout: create unparented branch by --orphan)Jakub Narebski, Mar 22, 2010
  13. Junio C HamanoMar 22, 2010

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.