4

I have tried a lot of different answers on stack but none of them work. I am trying to add a repository as a submodule which contains another submodule. So what I do is this:

git submodule add -b develop [email protected]:submoduleRepo 

The submodule is added to the repository and contains the folder of the submodule within it. However the folder is empty. So I follow up with this command:

git submodule update --init --recursive 

Which returns me nothing. If I go to the directory of the submodule cd submoduleRepo and then type git submodule, I get:

fatal: no submodule mapping found in .gitmodules for path 'src/app/nestedSubmoduleRepo' 

This is my .gitmodules of the main repo:

[submodule "submoduleRepo"] path = submoduleRepo url = [email protected]:submoduleRepo.git branch = develop 

And within submoduleRepo/.gitmodules:

[submodule ".\\src\\app\\nestedSubmoduleRepo"] path = .\\src\\app\\nestedSubmoduleRepo url = [email protected]:nestedSubmoduleRepo.git 

Why do I keep getting this error and is the directory not getting populated?

EDIT:

Once I've ran --init --recursive once it gives me the error:

fatal: No url found for submodule path 'submoduleRepo/src/app/nestedSubmoduleRepo' in .gitmodules Failed to recurse into submodule path 'submoduleRepo' 

My git config:

[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = [email protected]:mainRepo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [submodule "submoduleRepo"] url = [email protected]:submoduleRepo.git active = true 
2
  • That's not a url. Try giving the protocol, e.g. https://github.com/user/repo.git Commented Feb 19, 2020 at 15:21
  • That doesn't work either. Also, the submoduleRepo which contains the nestedSubmoduleRepo also has the url written that way and it does work. I am able to access that url. Commented Feb 19, 2020 at 15:25

1 Answer 1

5

The problem is that your submodule repo is using backslashes in the .gitmodules file. Git uses forward slashes for paths within the repository because they work across platforms (and backslashes do not), and it has no way of knowing whether your repository is intended to be cross platform or not.

You'll need to update the submodule repository to contain the proper entries in the file (and you should also drop the . path component as well). Once you've committed that and updated the parent repository with the new commit, git submodule update --init --recursive should work properly.

Sign up to request clarification or add additional context in comments.

1 Comment

src/app/nestedSubmoduleRepo then git submodule update --init --recursive did the trick! Thanks. Somewhat obvious but just in case someone struggles with it don't do git submodule update --recursive --init

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.