'fatal: not a git repository (or any of the parent directories): .git'
Asked Answered
P

5

17

fatal: not a git repository (or any of the parent directories): .git is the error I'm getting when I try to perform any git operation on my repository. I made some changes to my project which is the repository. Then I tried git status to look over my changes and encountered this error. I Googled this error but didn't make any progress. It seems this error is most common when trying to perform git operations in a directory that's outside the repository which isn't the case for me. Also I tried checking my ./git/HEAD and ./git/logs/refs/heads both of which are empty files. ./git/logs/refs/remotes/origin/master is also empty.

So from the beginning:

  • I made an Android project in this directory on one computer.
  • I initiated a git on this directory and posted it on github.
  • I followed the usual online guides for pulling this repository onto 2 other computers.
  • Made some changes on another computer, pushed the changes to the repository.
  • Then on the original computer I successfully pulled the changes.
  • After not working on the project for a few days, I made some changes on the original computer, tried to git status and this happened.
Phosphide answered 22/9, 2013 at 18:53 Comment(1)
Does this answer your question? Git: Receiving "fatal: Not a git repository" when attempting to remote add a Git repoKaltman
H
19

In my case, accidentally .git/HEAD file was messed up with non unknown characters, but .git/ORIG_HEAD file was ok (it has commit id). So, I copied .git/ORIG_HEAD content to .git/HEAD file. Then restarted IDE (Aptana) and everything worked fine.

Hackbut answered 24/3, 2014 at 8:45 Comment(3)
I ran into this issue when I saw a bunch of NULL characters in the .git/HEAD file after my computer crashed. The first symptom I noticed was a complete loss of everything in the history after seeing the "'git log' failed with code 128: fatal: Not a git repository..." message. This smooth move restored things.Faller
For me also the .git/ORIG_HEAD was damaged, but when you restore the .git/HEAD with a revision you think you had, everything works again and you can quickly figure out which branch/commit you actually were on.Shrinkage
I've got into same situation after blue screen of death. In my case copying contents from .git/ORIG_HEAD to .git/HEAD did not work. Solution was to manually update content of .git/HEAD to e.g. ref: refs/heads/your-branch-name. You can find your existing branches under .git/refs folder (can just copy path from there).Sprain
D
7

Make sure you don't have a GIT_DIR or GIT_WORK_TREE environment variable set in your current session, which would point to an incorrect folder.

In doubt, try a:

cd /path/to /your/repo
git --git-dir .git --work-tree . status

If that still fails, try at least to clone that repo again from GitHub, and add your recent changes in that new repo:

cd /path/to/new/clone
git --git-dir .git --work-tree /path/to /your/repo add .

(and go on working in that new clone)

Dramatize answered 22/9, 2013 at 19:21 Comment(4)
I can't use any git commands in my repo's path. Any git commands just returns that "not a repo" error. How else can I check my GIT_DIR or GIT_WORK_TREE?Phosphide
@user2804884 did your try the first git command I mentioned in my answer though?Dramatize
i tried that at my repo's path and it returned the error in questionPhosphide
@user2804884 does your repo path still contain a .git folder?Dramatize
A
6

I too had the same issue. The problem was my git folder was being synced by UbuntuOne cloud service. It had messed up the files by adding files appended with u1conflict. And my .git/HEAD was also messed up as .git/HEAD.u1conflict.

Are you using any cloud collaborating services on the git? Dropbox, UbuntuOne etc. Chances are that your .git folder might have got messed up in the process of syncing.

Abstain answered 14/10, 2013 at 15:54 Comment(0)
H
1

git init solved my issue. In fact, there was not any .git folder

Howrah answered 16/5, 2020 at 0:41 Comment(0)
Z
0

Ensure the directory/repository name has not changed in any way from the original. I just dealt with this error, and that was the cause.

Zelmazelten answered 19/7, 2018 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.