Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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 repo. I made some changes to my project which is the repo then I try to git status to look over my changes and encounter 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 repo 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 repo onto 2 other computers.
  • Made some changes on another computer, pushed the changes to the repo.
  • 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 happens.
like image 390
xyals Avatar asked Sep 22 '13 18:09

xyals


People also ask

How do I fix fatal not a git repository or any of the parent directories?

For the second situation, you need to initialize the Git repository in your project folder. To do so, you need to navigate to the correct folder and then run the command git init , which will create a new empty Git repository or reinitialize an existing one.

What does fatal not a git repository or any of the parent directories ): .git mean?

What does “fatal: not a git repository” mean? This error means you attempted to run a Git command, but weren't inside a Git repository. Make sure you've: Navigated to the right directory.

How do you fix does not appear to be a git repository?

Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.


2 Answers

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.

like image 63
Ikrom Avatar answered Oct 22 '22 09:10

Ikrom


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)

like image 35
VonC Avatar answered Oct 22 '22 10:10

VonC