70

When I run git submodule init, I get the following error:

No submodule mapping found in .gitmodules for path 'xxx'

I searched for a .gitmodules file and I cannot find it anywhere.

I have read this most popular SO question on the same topic. But unfortunately, I cannot solve the problem. Especially given that I no longer have .gitmodules.

According to my GitHub private repo, I still have submodules for my repository. Just that I cannot find the .gitmodules file anywhere.

1
  • 4
    I think it might be worth noting that you can create a submodule accidentally if you git init a new repo inside of an existing repo (the definition of a "submodule"). If you do this, the .gitmodule file won't be created.
    – tandy
    Commented Feb 18, 2014 at 22:33

3 Answers 3

163
  1. Make sure that there are no submodule sections in .git/config. If there are, remove them.
  2. Do git rm --cached <path_to_submodule>.
5
  • 13
    Just step 2 above was enough for me; git rm --cached <path_to_submodule> .
    – christosc
    Commented May 30, 2014 at 7:28
  • 1
    and just don't forget to git commit after the second step Commented May 16, 2016 at 9:03
  • 2
    Calling git rm --cached gives fatal: Please, stage your changes to .gitmodules or stash them to proceed. Commented Dec 27, 2016 at 17:56
  • 1
    @QuolonelQuestions I got that too .. git add .gitmodules will stage the file, then the git rm --cached <submodule_path> worked for me.
    – Neek
    Commented Jan 19, 2017 at 10:41
  • This worked for me as well. I was in the middle of a rebase and was still able to use this answer. Commented Feb 8, 2022 at 0:12
5

just got over the same issue yesterday, after having deleted by hand the entry in .gitmodules (e.g. nano .gitmodules), I had to go with

git rm --cached <pathtomodule> 

which returned a message

rm '<pathtomodule>'

then I needed a

git commit -m "delete cached modules"

and validated the submodule deletion.

3

In addition to the above I also had to remove .gitmodules.

1
  • In my case I didn't delete the entire file, but removed the now invalid entries and things started working again. Thanks! Commented Oct 24, 2016 at 22:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.