2

I have been working on the same local repository, cloned from remote origin, for several months. When I booted today, despite not changing anything, the repo is no longer being recognized by git. Attempting to run any git command anywhere in the repo gives this error:

fatal: Not a git repository (or any of the parent directories): .git

The .git directory still exists and looks valid at a glance, although I'm not really sure what I'm looking for in there.

I have made certain that:

  • I am running the commands in the right place.
  • The repo is initialized.

The first thing I did after I started getting these errors was to try and run git init in the repo root to reinitialize. When I do this, I get a message indicating that it was reinitialized successfully, but the repo is still not treated as such by git; I continue to get the error above.

A lot of in-progress local work remains in that repo and I would really rather not start from scratch on a fresh clone. What can I else can I do to fix this?

Edit: This is git running in Cygwin on Windows 10, if it matters.

MD Mooney
  • 21
  • 3
  • 2
    Make sure the file `HEAD` exists in `.git`. If it doesn't, create one reading `ref: refs/heads/master` to tell Git that you were on `master`, or `ref: refs/heads/foo` to tell Git that you were on `foo`. That's the usual problem when Git thinks the repo isn't a repo. If that's not it, there are a few more possibilities, but they're generally harder to recover from too. – torek Jun 07 '18 at 18:24
  • One possible cause is weird behavior with symlinks. Are you accessing the repo via a symlink rather than its canonical path? If so, try running the command at the other path. You should be able to see what directory Git thinks it’s in by running `git pwd` after [defining that command](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases) with `git config --global alias.pwd '!pwd'`. – Rory O'Kane Jun 07 '18 at 21:15
  • OP, any update? – evolutionxbox Jun 08 '18 at 08:40

1 Answers1

0

What solved it for me was @torek's suggestion in the comment. Although .git/HEAD existed already, I copied it as a backup and made a new HEAD with simply one line, ref: refs/heads/main and just like that, all the normal git commands were working agin.