Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "resolve fatal: Not a git repository"?

I was trying to remove one sub-module from the project

Tried rm -rf .git/modules/submodulePath

After that I am having the issue

fatal: Not a git repository

like image 346
coreDeviOS Avatar asked Jan 18 '17 11:01

coreDeviOS


People also ask

How do I fix the fatal not a git repository error?

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.

How do I resolve a repository not found?

Fix 5 - Git - remote: Repository not found Just run the git remote update command which updates the local repo with the remote repo and its credentials. If this command is executed without any issues then your issue will be resolved.

How resolve fatal Cannot be read from remote repository?

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication. To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.

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.


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.

Update:

1.) Delete the relevant section from the .gitmodules file. You can use below command:

git config -f .gitmodules --remove-section "submodule.submodule_name" 

2.) Stage the .gitmodules changes

git add .gitmodules 

3.) Delete the relevant section from .git/config. You can use below command:

git submodule deinit -f "submodule_name" 

4.) Remove the gitlink (no trailing slash):

git rm --cached path_to_submodule 

5.) Cleanup the .git/modules:

rm -rf .git/modules/path_to_submodule 

6.) Commit:

git commit -m "Removed submodule <name>" 

7.) Delete the now untracked submodule files

rm -rf path_to_submodule 
like image 128
Shivkumar kondi Avatar answered Sep 24 '22 10:09

Shivkumar kondi


I ran into this and didn't have a .git/modules directory in my main repository. I have one submodule 'build', so just removed any references and reinitialized it:

rm -rf .git/modules rm -rf build git submodule init git submodule update 
like image 45
Jason Goemaat Avatar answered Sep 25 '22 10:09

Jason Goemaat