how to start with non-master branch?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

how to start with non-master branch?

Rustom Mody
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 [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: how to start with non-master branch?

Dirk Süsserott
Am 19.07.2009 14:53 schrieb Rustom Mody:

> 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 [hidden email]
> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: how to start with non-master branch?

Sean Estabrooks
In reply to this post by Rustom Mody
On Sun, 19 Jul 2009 18:23:32 +0530
Rustom Mody <[hidden email]> wrote:

Hi Rustom,

> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: how to start with non-master branch?

Charles Bailey
In reply to this post by Rustom Mody
On Sun, Jul 19, 2009 at 06:23:32PM +0530, Rustom Mody wrote:

> 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/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: how to start with non-master branch?

MichaelJGruber
In reply to this post by Rustom Mody
Rustom Mody venit, vidit, dixit 19.07.2009 14:53:

> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html