Gabriel Sprenger Gabriel Sprenger - 2 months ago 20
Git Question

My project folder is no longer a Git repository

I am using Git for a project.
Up to yesterday night, the repository was up and running and I shut my computer down by the end of the day as I always do.

This morning, when trying to run

git status
from my project folder as I always do, I get this error:
fatal: not a git repository (or any of the parent directories): .git


I know that nothing happened between the moment I shut down my computer and boot it again this morning, so I'm confused about why the repository would vanish like that. It's worth nothing that the
.git
folder and
.gitignore
file are still present in the project folder.

Now my problem here is that even if I could do a fresh checkout of the repository in a new folder, I still have code that I stashed yesterday (using
git stash
), including a script of SQL queries that took me several hours to write and other pieces of code I don't even exactly remember what it is because I use stashing a lot to store unfinished work that's not yet ready to be committed.

I searched the Internet and specifically this place and found no one having the same issue, which makes it even more strange.

Answer Source

Obligatory question: Do you have a backup?

If not: bad.

If yes: Restore the backup of the repository to a different directory, check out the latest branch / commit you know you were working on, if there's a stash in that backup as well, commit it to a new branch. Then overwrite the source files in that branch with the source files of your damaged repository. This gives you the difference of the last undamaged, backed up state and whatever you did in the meantime. You can stash it as well.

For this very reason I normally commit early, often and push to an external repository as backup.