Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git status returns fatal: Not a git repository but .git exists and HEAD has proper permissions

Tags:

git

When I run git status on my repo I get fatal: Not a git repository: /my repo/.git/modules/docs

I've checked and .git exists and contains HEAD with the proper permissions. I can run various other commands fine. If I run git gui it opens fine and will list a couple of the changed files, but is missing a lot of them.

I'm guessing there may be some sort of corruption in HEAD, not sure though. Any idea how to fix this without wiping out the whole repo?

Update: I realized that I had changed the name of the repo's directory. The directory being referenced in the error is the old name of the directory. So my current repo is at /new dir/.git but the error is saying Not a git repository: /old dir/.git/modules/docs. So maybe git is confused?

like image 264
Josh Farneman Avatar asked Apr 13 '12 15:04

Josh Farneman


People also ask

How do I fix a fatal Not a git repository?

Check that you correctly created the repo. If the directory doesn't contain a . git repo, use git init to properly initialize the repo or clone an existing repo. Make sure your HEAD file contains the correct information on your current branch.

How do you solve please make sure you have the correct access rights and the repository exists?

The “Please make sure you have the correct access rights” error occurs if you do not have the right permissions to access a Git repository. To solve this error, make sure you are referring to the correct remote URL and that you have set up SSH authentication correctly.

How do I initialize a git repository?

Initializing a new repository: git init To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new . git subdirectory in your current working directory.


2 Answers

These two files contains absolute submodule path:

{submodule}/.git .git/modules/{submodule}/config 

So, if you moved the repo, the absolute path in these two files are not valid, and cause the 'not a git repository' error. Just fix these files manually.

like image 88
ax003d Avatar answered Sep 28 '22 23:09

ax003d


Former versions of git used an absolute path to locate the gitdir of a submodule. The solution is as follows:

  1. Upgrade git to the latest version. Some says you'll need at least version 1.7.10. I just successfully solved the issue with git 1.8.3.
  2. Delete all the broken submodule folders: rm -rf broken_submodule_folder
  3. Update the registered submodules: git submodule update. You should see the submodules being checked out.
like image 27
Maxime R. Avatar answered Sep 28 '22 21:09

Maxime R.