Re: Where is git checkout --orphan implemented at.
- Date: Tue, 5 Jun 2018 13:54:36 -0400
- From: Jeff King <peff@xxxxxxxx>
- Subject: Re: Where is git checkout --orphan implemented at.
On Tue, Jun 05, 2018 at 12:02:12PM -0400, Sean Hunt wrote:
> I would like to see the source code to git checkout --orphan so I can
> learn how it works and so I can manually do what it does by hand on
> making a new branch with no history in the refs folder. I can only do
> it on my iPhone as my laptop has no internet or way to do it there,
> and the program on my iPhone does not have the method implemented yet
> visually to do it, forcing manual creation of the orphan branch by
> hand in the end. If the public github had all the codes to all
> commands and subcommands like the one above it would be nice or well
> at least a file that explains the source file each command and
> subcommands are from so that way a person like me can use as a
> reference to make our own git gui that has 100% of command line git
The code for "checkout --orphan" is in builtin/checkout.c.
But if you want to do roughly the same thing with other tools, you can
git symbolic-ref HEAD refs/heads/new-branch
If you don't even have symbolic-ref handy, you can do:
echo "ref: refs/heads/new-branch" >.git/HEAD
That's not generally recommended, since future versions of Git may
change the ref storage format, but it would work with any current
version of Git.
 Try update_refs_for_switch(), especially: