Quickly Resolving “no url found for submodule path” Problems

“No url found for submodule path” errors can be tricky to track down; if you think you have all your submodules set up correctly. I ran into this very issue today! I cloned one of my team’s repositories and could not then pull the submodules due to this error. After some searching, I was able to find a simple solution to resolve the error from incorrectly adding submodules to your repository.

man in white shirt using macbook pro
Photo by Tim Gouw on Pexels.com

The problem I was running into was this:

$ git submodule update --init --recursive
fatal: No url found for submodule path 'common_source' in .gitmodulesCode language: JavaScript (javascript)

I was left scratching my head because I did in fact have my .gitmodules set correctly. I should not have been seeing this “No url found for submodule path” error.

The normal resolution did not help:

git rm --cached modules/common_source
git add git@<my-common-source-submodule-repo-url>/common_source.git modules/common_sourceCode language: HTML, XML (xml)

This would resolve my issue for my local repository, but if I then cloned it anew I would run into the same problem.

I finally found the magic sauce from this post on Netlify. (Note: Gitlinks, which are submodules, have mode 160000).

$ git ls-files --stage | grep 160000
14:160000 9e05e5731986604b50a1bf4a6201aec642f76a27 0	common_source
270:160000 9e05e5731986604b50a1bf4a6201aec642f76a27 0	modules/common_source

Somehow, I’m not sure how, but somehow the submodule got added at the wrong path initially and then was not correctly removed. Using the git ls-files command, I was able to see that the submodule was indeed listed twice. That was what was causing the error.

To fix this once and for all, I did this:

$ git rm --cached common_source

And, viola! Problem solved!


I hope that someone else can find this helpful!

Comments

One response to “Quickly Resolving “no url found for submodule path” Problems”

  1. Rain Avatar

    Thank you so much for writing this, I had this issue with my repoisitory and this was the only article that actually helped me. I cannot thank you enough.

Leave a Reply

Your email address will not be published. Required fields are marked *