3

I've got a strange problem: tried to make a new repository, as usual, followed instructions from github:

  1. git init
  2. git add .
  3. git commit -m "first commit"
  4. git remote add origin https://github.com/*/**.git
  5. git push -u origin master

My problem occures at the 3rd step:

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' "Branch could not be empty."

What's the matter? I didn't have such problem until now. Tried to reinit git by deleting the folder and typing new "git init" command - the problem still the same.

p.s.: the full way of making repository I've passed: got to the github.com, clicked on the button "New" (repository), added a name for it (the same as a folder on PC) and started to do some magic via cmder (following the instructions from github) ...

p.p.s.: I use windows 10 and cmder (tried gitBash too).

upd: there's something in my windows environment, 'cause on another machine everything's fine.

Kate
  • 31
  • 5
  • 1
    Perhaps the error is with your shell? http://stackoverflow.com/questions/12267912/git-fatal-ambiguous-argument-head-unknown-revision-or-path-not-in-the-workin – cmbuckley Mar 16 '16 at 10:46
  • Wow, i'm russian and a newbie (double trouble :D), yep, i've found this answer, but don't know what exactly I need to do? I'm talking about Jacob Helwig's answer. Where should I past his last code in my shell (I've got Windows and cmder, if it matters) to try his solution? – Kate Mar 16 '16 at 11:08
  • It sounds like a shell helper function (perhaps something that adds git info to your PS1: see http://stackoverflow.com/questions/10133173/alter-git-prompt-on-windows) is calling something like `git rev-parse HEAD` somewhere. In any case you needn't worry about it as the error is only with the shell extension, not with git itself. Run `git log` after step 3 and you should see that your first commit is there! – cmbuckley Mar 16 '16 at 11:12
  • After "git log" my shell says >fatal: your current branch appears to be broken. That means the problem is not in my shell, but in git? Or you'll advise to dig deep in shell? – Kate Mar 16 '16 at 11:26
  • 1
    Wow, looks like the shell is completely breaking your git repo. I'd advise updating the question with more info about the Windows environment you're using. And seeing as I know nothing about Windows shells I'm now not going to be much use to you ;-) – cmbuckley Mar 16 '16 at 11:30
  • Can you give this a try git commit -m"first commit" without a space between -m and "first commit" comment? It should not matter really. But a hazy memory that I faced a similar issue. – Atul Mar 16 '16 at 12:28
  • Atul, that didn't work ;( – Kate Mar 16 '16 at 13:21

1 Answers1

0

Do you have any files in the directory where you are creating your Git repo, or were you planning to add those later? To create a commit, Git must have a file to commit, whether it is in the repository's root directory or a subdirectory. Just having a directory will not work, and that includes the root directory alone. (This would explain why merely creating a new directory and initializing a git repository inside of it produced the same results.)

Once you have a file in your directory somewhere, start again at step 2. Hopefully, that should get you going.

P.S. What version of git do you have? The one I have on windows is 2.9.2.windows.1. When I do Steps 1-3 inside an empty directory, I get this output:

On branch master

Initial commit

nothing to commit

It may be that later versions have changed to make the error message more indicative of the real problem.

John Chesshir
  • 590
  • 5
  • 20