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


These two files contains absolute submodule path:


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.


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

Answered By – Shivkumar kondi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published