# Re: Parent-less branches

4 messages from 2008-05-02 to 2008-05-04. Participants: Ulrik Sverdrup, Jakub Narebski, Sverre Rabbelier, Daniel Barkalow.
Thread: https://gitlist.dev/t/13359

## Ulrik Sverdrup, 2008-05-02 23:20

Subject: Re: Parent-less branches
Message-ID: <20080502232008.GA20092@ulrik-ibook>
URL: https://gitlist.dev/e/20080502232008.GA20092%40ulrik-ibook

```
> I wanted to do this just the other day, but I did it all inside the  
> one repo, and made some notes on the process here:
> 
> http://rails.wincent.com/wiki/Creating_independent_branches_with_Git
> 
> Basically, using "git write-tree" and "git commit-tree" plumbing.
> 
> Cheers,
> Wincent

I think I've seen this done much simpler, in this blog post:

http://madduck.net/blog/2007.07.11:creating-a-git-branch-without-ancestry/

Even though your instructions seem more complicated than they are since
they mix setting up the parentless branch and preparing the first
commit content.

regards,
ulrik

(I am not on the list, please CC)

```

## Jakub Narebski, 2008-05-03 00:17

Subject: Re: Parent-less branches
Message-ID: <m38wys6y1q.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m38wys6y1q.fsf%40localhost.localdomain
In-Reply-To: <20080502232008.GA20092@ulrik-ibook>

```
Ulrik Sverdrup <ulrik.sverdrup@gmail.com> writes:
> Wincent Colaiuta <win@wincent.com> writes:
>>
>> I wanted to do this just the other day, but I did it all inside the  
>> one repo, and made some notes on the process here:
>> 
>> http://rails.wincent.com/wiki/Creating_independent_branches_with_Git
>> 
>> Basically, using "git write-tree" and "git commit-tree" plumbing.
> 
> I think I've seen this done much simpler, in this blog post:
> 
> http://madduck.net/blog/2007.07.11:creating-a-git-branch-without-ancestry/

And it is mentioned in http://git.or.cz/gitwiki/BlogPosts, athough not
yet in either GitTips or GitFaq.


In short the solution is to create content-less branch using:

  $ git symbolic-ref HEAD refs/heads/newbranch
  $ rm .git/index
 
then commit.

> Even though your instructions seem more complicated than they are since
> they mix setting up the parentless branch and preparing the first
> commit content.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Sverre Rabbelier, 2008-05-03 00:46

Subject: Re: Parent-less branches
Message-ID: <bd6139dc0805021746q40b384c3nb36a8605d9475a7f@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0805021746q40b384c3nb36a8605d9475a7f%40mail.gmail.com
In-Reply-To: <m38wys6y1q.fsf@localhost.localdomain>

```
On Sat, May 3, 2008 at 2:17 AM, Jakub Narebski <jnareb@gmail.com> wrote:
>  In short the solution is to create content-less branch using:
>
>   $ git symbolic-ref HEAD refs/heads/newbranch
>   $ rm .git/index
>
>  then commit.

I guess what Pedro is asking is if there isn't a builtin way to do
this. Which, if I understand correctly, there isn't. Perhaps though
something like "git branch -N newbranchname" which then creates a new
parentless branch. It could just be a shell script that does the
above, but I wonder if there are no side-effects of the above? It
sounds somewhat 'messy' to remove the index? Too 'low level' to do for
a user I mean, what if sometime in the future we decide to store
something in the index that -is- important? I reckon it would be
cleaner to add an option for this.

-- 
Cheers,

Sverre Rabbelier

```

## Daniel Barkalow, 2008-05-04 05:50

Subject: Re: Parent-less branches
Message-ID: <alpine.LNX.1.00.0805040139310.19665@iabervon.org>
URL: https://gitlist.dev/e/alpine.LNX.1.00.0805040139310.19665%40iabervon.org
In-Reply-To: <bd6139dc0805021746q40b384c3nb36a8605d9475a7f@mail.gmail.com>

```
On Sat, 3 May 2008, Sverre Rabbelier wrote:

> On Sat, May 3, 2008 at 2:17 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> >  In short the solution is to create content-less branch using:
> >
> >   $ git symbolic-ref HEAD refs/heads/newbranch
> >   $ rm .git/index
> >
> >  then commit.
> 
> I guess what Pedro is asking is if there isn't a builtin way to do
> this. Which, if I understand correctly, there isn't. Perhaps though
> something like "git branch -N newbranchname" which then creates a new
> parentless branch. It could just be a shell script that does the
> above, but I wonder if there are no side-effects of the above? It
> sounds somewhat 'messy' to remove the index? Too 'low level' to do for
> a user I mean, what if sometime in the future we decide to store
> something in the index that -is- important? I reckon it would be
> cleaner to add an option for this.

If sometime in the future we decide to store something in the index that 
is important, we'll definitely want to remove the index, because whatever 
it is will be both important and -wrong- for a new parentless commit, 
since a new root should have all the default values, not values acquired 
during the other history in the repo.

On the other hand, a builtin command of that sort probably ought to make 
sure that there aren't any uncommitted changes before doing this. And it 
should probably be called "git checkout -b name -N", since it makes it 
your current branch, rather than creating it like "git branch ..." would 
suggest.

	-Daniel
*This .sig left intentionally blank*

```
