Receiving "fatal: Not a git repository" when attempting to remote add a Git repo

admin

NOTE: this does not answer to tướng the common problem, which was OP’s problem, but to tướng different problem where this error message may come up. I didn’t feel lượt thích doing new question just to tướng write this answer down, tell bu if I should tự that instead :P

I got to tướng situation, most likely due to tướng 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 mặc định revision 'HEAD'. Remotes were there though, sánh I did git fetch --all and then just git reset --hard origin/master to tướng get myself to tướng the state the repo was previously.

Note that if there is some uncommitted changes, you can see them with git status, git diff and sánh on. Then just git diff yourfile > patch before running the reset.

At least for bu reflog (git reflog) disappeared completely. Hence, if you tự the reset, and there was some changes you wanted to tướng 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.