NOTE: this does not answer to the common problem, which was OP’s problem, but to different problem where this error message may come up. I didn’t feel like doing new question just to write this answer down, tell me if I should do that instead :P
I got to situation, most likely due to some corruption of certain crash I had, that I got this error even when .git did exist.
smar@aaeru ~/P/Nominatim> git status fatal: Not a git repository (or any of the parent directories): .git smar@aaeru ~/P/Nominatim [128]> ls .git COMMIT_EDITMSG config* FETCH_HEAD HEAD index logs/ modules/ objects/ ORIG_HEAD packed-refs
Since I didn’t have anything that really needed preserving, I just went with dummy way, and did...
smar@aaeru ~/P/Nominatim [128]> git init Reinitialized existing Git repository in /home/smar/Projektit/Nominatim/.git/
Still not working though, as for example git log returns fatal: bad default revision 'HEAD'. Remotes were there though, so I did git fetch --all and then just git reset --hard origin/master to get myself to the state the repo was previously.
Note that if there is some uncommitted changes, you can see them with git status, git diff and so on. Then just git diff yourfile > patch before running the reset.
At least for me reflog (git reflog) disappeared completely. Hence, if you do the reset, and there was some changes you wanted to prevent, I’m not sure you can get them back after reset anymore. So, make sure that you have all changes you can’t lose backed up, ultimately by just copying the clone before trying this.
git initbut also make sure none of your subdirectories have their own.gitfolder