# How can I create a commit without a parent?

5 messages from 2010-02-02 to 2010-02-02. Participants: Ron Garret, Junio C Hamano, Jakub Narebski, Jay Soffian.
Thread: https://gitlist.dev/t/22480

## Ron Garret, 2010-02-02 08:00

Subject: How can I create a commit without a parent?
Message-ID: <ron1-5383E3.00002602022010@news.gmane.org>
URL: https://gitlist.dev/e/ron1-5383E3.00002602022010%40news.gmane.org

```
SLSIA.  git commit-tree insists on having at least one parent commit at 
the command line.  From reverse-engineering it seems like I could do it 
by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but 
mucking with HEAD directly like that feels kinda scary.

Thanks,
rg

```

## Junio C Hamano, 2010-02-02 08:05

Subject: Re: How can I create a commit without a parent?
Message-ID: <7vwryw6p16.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwryw6p16.fsf%40alter.siamese.dyndns.org
In-Reply-To: <ron1-5383E3.00002602022010@news.gmane.org>

```
Ron Garret <ron1@flownet.com> writes:

> git commit-tree insists on having at least one parent commit at 
> the command line.

Incorrect.  "git commit" might but "git commit-tree" does.  Perhaps you
are forgetting that the first object name is a tree to be wrapped.

A short answer is that you don't create a root commit twice in a single
repository, period.  Your repository _may_ be end up with more than one
root but that typically is due to you fetching unrelated histories from
different repositories, each created its own root.

```

## Ron Garret, 2010-02-02 08:19

Subject: Re: How can I create a commit without a parent?
Message-ID: <ron1-2FA457.00192402022010@news.gmane.org>
URL: https://gitlist.dev/e/ron1-2FA457.00192402022010%40news.gmane.org
In-Reply-To: <7vwryw6p16.fsf@alter.siamese.dyndns.org>

```
In article <7vwryw6p16.fsf@alter.siamese.dyndns.org>,
 Junio C Hamano <gitster@pobox.com> wrote:

> Ron Garret <ron1@flownet.com> writes:
> 
> > git commit-tree insists on having at least one parent commit at 
> > the command line.
> 
> Incorrect.  "git commit" might but "git commit-tree" does.  Perhaps you
> are forgetting that the first object name is a tree to be wrapped.

No, I didn't forget that.  I forgot to omit the -p flag.  Doh!

> A short answer is that you don't create a root commit twice in a single
> repository, period.

Why not?  I could easily create an empty root commit and multiple 
branches off that.  (Maybe that's a better way to go.)  What would be 
the difference?

rg

```

## Jakub Narebski, 2010-02-02 15:02

Subject: Re: How can I create a commit without a parent?
Message-ID: <m3zl3radgl.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3zl3radgl.fsf%40localhost.localdomain
In-Reply-To: <ron1-5383E3.00002602022010@news.gmane.org>

```
Ron Garret <ron1@flownet.com> writes:

> SLSIA.  git commit-tree insists on having at least one parent commit at 
> the command line.  From reverse-engineering it seems like I could do it 
> by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but 
> mucking with HEAD directly like that feels kinda scary.

You have git-symbolic-ref to set HEAD directly (don't forget to remove
index).  

Or you can set up / initialize separate (new) repository, create
commit there and then pull this new repository into current one.


P.S. Creating new root (parentless) commit isn't something that you do
on purpose, usually.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Jay Soffian, 2010-02-02 16:40

Subject: Re: How can I create a commit without a parent?
Message-ID: <76718491002020840y16d62fb5qc4f6c51602dac94f@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002020840y16d62fb5qc4f6c51602dac94f%40mail.gmail.com
In-Reply-To: <ron1-5383E3.00002602022010@news.gmane.org>

```
On Tue, Feb 2, 2010 at 3:00 AM, Ron Garret <ron1@flownet.com> wrote:
> SLSIA.  git commit-tree insists on having at least one parent commit at
> the command line.  From reverse-engineering it seems like I could do it
> by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but
> mucking with HEAD directly like that feels kinda scary.

I guess you're looking to do it with plumbing, but with porcelain the
way I'd do it is:

$ git init foo
$ git init bar
$ cd bar
$ git commit --allow-empty -m "empty bar root commit"
$ cd ../foo
$ git commit --allow-empty -m "empty foo root commit"
$ git fetch ../bar master:bar

j.

```
