Reputation: 229
I just jumped back into a project that I've been using Git on for about 6 months and saw this:
$ cd /d/DEVELOP/BlenderAe # My repo root
$ git status
fatal: not a git repository (or any of the parent directories): .git
That's definitely the right path, why does git not recognise my local clone?
My last actions were:
The git folder contents are as follows:
$ cd /d/DEVELOP/BlenderAe # My repo root
$ ls .git
ORIG_HEAD objects/ refs/
I do have the current code (backed it up, outside of git). How do I reconnect? And also to my github remote?
After fixing ORIG_HEAD
I see:
$ git status
Not currently on any branch.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: (old_file1).py
...all the older files that were previously renamed/deleted are listed here for deletion.
Untracked files:
(use "git add <file>..." to include in what will be committed)
Current_file1.py
...all the current files are listed here as untracked.
Upvotes: 5
Views: 6358
Reputation: 66178
.git/HEAD
is misssing
ls .git
showsORIG_HEAD objects/ refs/
That's incomplete, compare:
$ git init
$ tree .git
.git
├── HEAD
├── config
├── description
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── fsmonitor-watchman.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── pre-merge-commit.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ ├── pre-receive.sample
│ ├── prepare-commit-msg.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
8 directories, 16 files
The file missing which git is looking for to detect the git repo is HEAD
.
$ mv .git/HEAD .git/ORIG_HEAD
$ git status
fatal: not a git repository (or any of the parent directories): .git
ORIG_HEAD
The presence of ORIG_HEAD
suggests git was left in the act of doing something destructive, to recover from that (or possibly to see the next problem 🤞not):
$ mv .git/ORIG_HEAD .git/HEAD
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
If the HEAD
file is missing and there isn't an ORIG_HEAD
file - that's still recoverable if that's the only problem. The HEAD
file is plain text and indicates what branch is currently checked out:
Usually the HEAD file is a symbolic reference to the branch you’re currently on
example:
$ cat .git/HEAD
ref: refs/heads/main
Creating .git/HEAD
with that content (replacing main
with any valid branch name) will allow operating on the git repo, if the other contents of the git repo (the .git/objects
and .git/refs
folder contents) still exist.
Upvotes: 7