# Re: creating a new branch without an ancestor

4 messages from 2010-02-05 to 2010-02-05. Participants: Jay Soffian, Larry D'Anna, Michael Wookey, Wesley J. Landaker.
Thread: https://gitlist.dev/t/22528

## Michael Wookey, 2010-02-05 03:19

Subject: creating a new branch without an ancestor
Message-ID: <d2e97e801002041919r2043d05cjfb114a466605d9a1@mail.gmail.com>
URL: https://gitlist.dev/e/d2e97e801002041919r2043d05cjfb114a466605d9a1%40mail.gmail.com

```
Maybe I'm missing something from reading the docs, but I couldn't see
how to create a new branch in an existing repo that has no ancestor. I
would like to do something like what git.git does with some of the
other ancillary branches like "man", "html", and "todo".

I was hoping to do something like "git branch --no-ancestor
new-branch-name" but didn't see anything in the documentation that
describes the necessary branch options.

Or, am I looking in the wrong place?

```

## Larry D'Anna, 2010-02-05 03:24

Subject: Re: creating a new branch without an ancestor
Message-ID: <20100205032429.GA23285@cthulhu>
URL: https://gitlist.dev/e/20100205032429.GA23285%40cthulhu
In-Reply-To: <d2e97e801002041919r2043d05cjfb114a466605d9a1@mail.gmail.com>

```
* Michael Wookey (michaelwookey@gmail.com) [100204 22:20]:
> Maybe I'm missing something from reading the docs, but I couldn't see
> how to create a new branch in an existing repo that has no ancestor. I
> would like to do something like what git.git does with some of the
> other ancillary branches like "man", "html", and "todo".
> 
> I was hoping to do something like "git branch --no-ancestor
> new-branch-name" but didn't see anything in the documentation that
> describes the necessary branch options.
> 
> Or, am I looking in the wrong place?

git symbolic-ref HEAD refs/heads/whatever

That'll leave your index and working tree alone of course, so if you did a
commit right after that it would match the content of your current branch but
not the history.

    --larry

```

## Jay Soffian, 2010-02-05 03:32

Subject: Re: creating a new branch without an ancestor
Message-ID: <76718491002041932m3398abdel85bd1f4e1eb96899@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002041932m3398abdel85bd1f4e1eb96899%40mail.gmail.com
In-Reply-To: <20100205032429.GA23285@cthulhu>

```
On Thu, Feb 4, 2010 at 10:24 PM, Larry D'Anna <larry@elder-gods.org> wrote:
> * Michael Wookey (michaelwookey@gmail.com) [100204 22:20]:
>> Maybe I'm missing something from reading the docs, but I couldn't see
>> how to create a new branch in an existing repo that has no ancestor. I
>> would like to do something like what git.git does with some of the
>> other ancillary branches like "man", "html", and "todo".
>>
>> I was hoping to do something like "git branch --no-ancestor
>> new-branch-name" but didn't see anything in the documentation that
>> describes the necessary branch options.
>>
>> Or, am I looking in the wrong place?
>
> git symbolic-ref HEAD refs/heads/whatever
>
> That'll leave your index and working tree alone of course, so if you did a
> commit right after that it would match the content of your current branch but
> not the history.

You can also create the branch in a new repo, then just fetch that
into your existing repo.

j.

```

## Wesley J. Landaker, 2010-02-05 18:38

Subject: Re: creating a new branch without an ancestor
Message-ID: <80b2e7a2e4025acdad6e869fdeb9aab7.squirrel@webmail.icecavern.net>
URL: https://gitlist.dev/e/80b2e7a2e4025acdad6e869fdeb9aab7.squirrel%40webmail.icecavern.net
In-Reply-To: <d2e97e801002041919r2043d05cjfb114a466605d9a1@mail.gmail.com>

```
On Thu, February 4, 2010 20:19, Michael Wookey wrote:
> Maybe I'm missing something from reading the docs, but I couldn't see
> how to create a new branch in an existing repo that has no ancestor. I
> would like to do something like what git.git does with some of the
> other ancillary branches like "man", "html", and "todo".
>
> I was hoping to do something like "git branch --no-ancestor
> new-branch-name" but didn't see anything in the documentation that
> describes the necessary branch options.
>
> Or, am I looking in the wrong place?

I do this all the time for various reasons, so I made myself a
"git-emptybranch" command and stuck it in my path. Besides the error
checking, this just creates a new ref and clears the index so you can
start from a clean slate. No actual files are deleted from the work-tree.

$ cat ~/bin/git-emptybranch
#!/bin/sh
if [ $# -ne 1 ]; then
  2<&1
  echo "usage: git emptybranch <new_branch>"
  exit 1
fi

if ! git check-ref-format refs/heads/"$1"; then
  2<&1
  echo "fatal: '$1' is not a valid branch name."
  exit 1
fi

git symbolic-ref -m "git emptybranch $1" HEAD refs/heads/"$1"
git rm --cached -r -q --ignore-unmatch -- '*'

```
