I'm trying to initialize a new GIT repo from Debian (actually a VM on Virtualbox, installed and running on Mac OS X) :
[david@server-VM-001:~ $] mkdir test
[david@server-VM-001:~ $] cd test
[david@server-VM-001:test $] git init
Initialized empty Git repository in /home/david/test/.git/
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
[david@server-VM-001:test (master #) $]
What's the problem?
As others pointed out, this message is coming from your shell prompt. The problem is that in a freshly created repository
HEAD
(.git/HEAD
) points to a ref that doesn't exist yet.It looks like
rev-parse
is being used without sufficient error checking before-hand. After the first commit has been created.git/refs/heads
looks a bit different andgit rev-parse HEAD
will no longer fail.In the function that updates the Git information for the rest of my shell prompt (heavily modified version of wunjo prompt theme for ZSH), I have the following to get around this:
I had same issue and I solved it by "pod setup" after installing cocoapods.
I had this issue when having a custom display in my terminal when creating a new git project (I have my branch display before the pathname e.g. :/current/path). All I needed to do was do my initial commit to my master branch to get this message to go away.
I usually use git on my linux machine, but at work I have to use Windows. I had the same problem when trying to commit the first commit in a Windows environment.
For those still facing this problem, I was able to resolve it as follows:
Jacob Helwig mentions in his answer that:
Commit 62f162f from Jeff King (
peff
) should improve the robustness ofgit rev-parse
in Git 1.9/2.0 (Q1 2014) (in addition of commit 1418567):