Saturday, December 4, 2010

Git Gotta

>> mkdir foo
>> git init
Initialized empty Git repository in /home/jianlu/repos/web/foo/.git
>> git branch master
fatal: Not a valid object name: 'master'.

// How to fix this?
// make an arbitrary checkin by git submit. You are done.

Update:
git commit --allow-empty -m "initial commit"

Source of this update: (thanks to Mohamed Meligy's tip)

>> git branch
master.

Git claims this to be by design because before the user makes the first initial commit, there is nothing to be branched.

This kinda makes sense but not always a valid restriction. It is not a rare case that you want to lay out your repository structure because you know the repro structure should be like that even before you write the first line of your project code.

and btw, this is a terrible error message. It barely says anything about the real cause of this failure, or any suggestion on possible fixes.

2 comments:

Mohamed Meligy said...

You are likely way ahead of it, but for future readers coming from search engines like me:

If you really want an empty master branch to start with, you can do an empty commit like:

git commit --allow-empty -m "initial commit"

Then you can easily branch and everything.

This is where I found the tip:
http://stackoverflow.com/questions/5678699/creating-branches-on-an-empty-project-in-git

xTristan said...

thank you for the tips!