threads / discuss / 20157

how to start with non-master branch?

Subject: how to start with non-master branch?

## tl;dr

5 messages between Jul 19, 2009 and Jul 19, 2009.

replies: 4people: 5as markdown or json

Rustom Mody· Jul 19, 2009, 12:53 UTC · lore

I want my first commit to be on a non-master branch. So after the git init I do $ git checkout -b newbranch

I get fatal: You are on a branch yet to be born

Of course I can get by with making the first commit on master and then switching.

But wondering if I am missing something basic?
Dirk Süsserott· Jul 19, 2009, 16:13 UTC · re: Rustom Mody · lore

Re: how to start with non-master branch?

Am 19.07.2009 14:53 schrieb Rustom Mody:
Show 16 quoted lines
> I want my first commit to be on a non-master branch.
> So after the git init I do
> $ git checkout -b newbranch
> 
> I get
> fatal: You are on a branch yet to be born
> 
> Of course I can get by with making the first commit on master and then
> switching.
> 
> But wondering if I am missing something basic?
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

What about renaming the "initial master", i.e.: git init git add . git commit -m "intial checkin" git branch -m non-master-branch

and later adding a master just as any other branch, i.e. git checkout -b master

Unfortunately renaming doesn't work before the first commit, I got an error similar to yours.

I think the name "master" is just a convention and there's nothing special about that branch. Could've been called "main" or sth. as well when Linus invented it.

Dirk
Sean Estabrooks· Jul 19, 2009, 16:19 UTC · re: Rustom Mody · lore

Re: how to start with non-master branch?

On Sun, 19 Jul 2009 18:23:32 +0530 Rustom Mody <rustompmody@gmail.com> wrote:

Hi Rustom,
Show 6 quoted lines
> I want my first commit to be on a non-master branch.
> So after the git init I do
> $ git checkout -b newbranch
> 
> I get
> fatal: You are on a branch yet to be born

No branches exist in a new repository that you've just init'ed. If you run "git branch" you'll see that no branches are listed. You must make an initial commit before a branch will be "born". Since "git checkout" needs you to supply a branch/commit to operate, you can't use it to create the first branch in a repo.

When you make the initial commit in a repo the HEAD reference will determine which branch is created. So the following ugly looking command will allow you to change the name to something other than master before making your first commit:

	$ git symbolic-ref HEAD refs/heads/newbranch
> Of course I can get by with making the first commit on master and then
> switching.

That is probably the simplest thing to do, rename master after the initial commit:

	$ git commit -m "initial commit"
	$ git branch -m newbranch

HTH, Sean

Charles Bailey· Jul 19, 2009, 17:44 UTC · re: Rustom Mody · lore

Re: how to start with non-master branch?

On Sun, Jul 19, 2009 at 06:23:32PM +0530, Rustom Mody wrote:
Show 11 quoted lines
> I want my first commit to be on a non-master branch.
> So after the git init I do
> $ git checkout -b newbranch
> 
> I get
> fatal: You are on a branch yet to be born
> 
> Of course I can get by with making the first commit on master and then
> switching.
> 
> But wondering if I am missing something basic?

The problem with git checkout -b newbranch is that it tries to create a new branch based on your current HEAD. As you have no commits, your HEAD doesn't point at a commit ant this can't work. To change the name of your current branch before you've made any commits, you can use the symbolic-ref command to update your HEAD to point to a differently named branch (that also doesn't yet exist). Try this:

git symbolic-ref HEAD refs/heads/non-master
and then carry on adding and committing as before.
Charles.
-- 
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
Michael J Gruber· Jul 19, 2009, 18:26 UTC · re: Rustom Mody · lore

Re: how to start with non-master branch?

Rustom Mody venit, vidit, dixit 19.07.2009 14:53:
Show 11 quoted lines
> I want my first commit to be on a non-master branch.
> So after the git init I do
> $ git checkout -b newbranch
> 
> I get
> fatal: You are on a branch yet to be born
> 
> Of course I can get by with making the first commit on master and then
> switching.
> 
> But wondering if I am missing something basic?
You can do
git symbolic-ref HEAD refs/heads/newbranch

and your first commit will be to that branch. (checkout as above tries to branch off the non-existing branch master.)

Cheers, Michael

← back to recent threads