No submodule mapping found in .gitmodule for a path that's not a submodule

GitGit Submodules

Git Problem Overview


I have a project that has a submodule at lib/three20

My .gitmodule file looks like this:

[submodule "lib/three20"]
	path = lib/three20
	url = git://github.com/facebook/three20.git

I have cloned this in the past without errors, (git submodule init followed by a git submodule update) and it's been working for a while.

I tried to clone this to a new machine, and now I'm getting this error on git submodule init:

No submodule mapping found in .gitmodules for path 'Classes/Support/Three20'

That path is just an empty folder in Xcode that I use to house the projects from the other directory. It's not part of the .gitmodules file, so I don't see where it's getting this path from.

Any ideas?

Git Solutions


Solution 1 - Git

No submodule mapping found in .gitmodules for path 'OtherLibrary/MKStore' when

$ git submodule update --init

I didn't know why the error occur. After spending a minute and found the answer in stackoverflow.

$ git rm --cached OtherLibrary/MKStore

and then update the submodule again. It's working fine.

http://en.saturngod.net/no-submodule-mapping-found-in-gitmodules

Solution 2 - Git

Following rajibchowdhury's answer (upvoted), use git rm command which is advised is for removing the special entry in the index indicating a submodule (a 'folder' with a special mode 160000).

If that special entry path isn't referenced in the .gitmodule (like 'Classes/Support/Three20' in the original question), then you need to remove it, in order to avoid the "No submodule mapping found in .gitmodules for path" error message.

You can check all the entries in the index which are referencing submodules:

git ls-files --stage | grep 160000

Previous answer (November 2010)

It is possible that you haven't declared your initial submodule correctly (i.e. without any tail '/' at the end, as described in my old answer, even though your .gitmodule has paths which looks ok in it).

This thread mentions:

> do you get the same error when running 'git submodule init' from a fresh clone?
If so, you have something wrong.

> If you have no submodules, delete .gitmodules, and any references to submodules in .git/config, and ensure the Pikimal dir does not have a .git dir in it.
If that fixes the problem, check in and do the same on your cruise working copy.

Obviously, don't delete your main .gitmodules file, but look after other extra .gitmodules files in your working tree.


Still in the topic of "incorrect submodule initialization", Jefromi mentions submodules which actually are gitlinks.

See How to track untracked content? in order to convert such a directory to a real submodule.

Solution 3 - Git

When I use SourceTree to do the stuff, it will spit out this message.
The message that I encountered:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree submodule update --init --recursive
No submodule mapping found in .gitmodules for path 'SampleProject/SampleProject'
Completed with errors, see above

My scenario is I misapplied the project directory the contains .git folder.
SourceTree regarded this folder as git submodule, but actually not.

My solution is use command line to remove it.

$ git rm -r SampleProject --cached
$ git commit -m "clean up folders"

remove the garbage in git and keep it clean.

Solution 4 - Git

I resolved this issue for me. Initially I tried to do this:

git submodule add --branch master [URL] [PATH_TO_SUBMODULE]

As it turns out the specification of the --branch option should not be used if you want to clone the master branch. It throws this error:

fatal: Cannot force update the current branch.
Unable to checkout submodule '[PATH_TO_SUBMODULE]'

Every time you try to do a

git submodule sync

This error will be thrown:

No submodule mapping found in .gitmodules for path '[PATH_TO_SUBMODULE]'

And the lines needed in .gitmodules are never added.

So the solution for me was this:

git submodule add [URL] [PATH_TO_SUBMODULE]

Solution 5 - Git

in the file .gitmodules, I replaced string

"path = thirdsrc\boost" 

with

"path = thirdsrc/boost", 

and it solved! - -

Solution 6 - Git

I just hit this error after trying to "git submodule init" on a new checkout of my repo. Turns out I had specified the module sub-folder with the wrong case initially. Since I'm on a Mac with a case-sensitive filesystem (hurr) it was failing. For example:

git submodule add git@github.com:user/project.git MyApp/Resources/Project
Cloning into 'MyApp/Resources/Project'

succeeds but the trouble is that on disk the path is

Myapp/Resources/Project

What I don't understand is why git is init'ing the module to wrong folder (ignoring the incorrect case in my command) but then operating correctly (by failing) with subsequent commands.

Solution 7 - Git

Just git rm subdir will be ok. that will remove the subdir as an index.

Solution 8 - Git

Just had this problem. For a while I tried the advice about removing the path, git removing the path, removing .gitmodules, removing the entry from .git/config, adding the submodule back, then committing and pushing the change. It was puzzling because it looked like no change when I did "git commit -a" so I tried pushing just the removal, then pushing the readdition to make it look like a change.

After a while I noticed by accident that after removing everything, if I ran "git submodule update --init", it had a message about a specific name that git should no longer have had any reference to: the name of the repository the submodule was linking to, not the path name it was checking it out to. Grepping revealed that this reference was in .git/index. So I ran "git rm --cached repo-name" and then readded the module. When I committed this time, the commit message included a change that it was deleting this unexpected object. After that it works fine.

Not sure what happened, I'm guessing someone misused the git submodule command, maybe reversing the arguments. Could have been me even... Hope this helps someone!

Solution 9 - Git

The folder mapping can be found in .git/modules folder (each has config file with reference to its worktree), so make sure these folders correspond to the configuration in .gitmodules and .git/config.

So .gitmodules has the correct path:

[submodule "<path>"]
  path = <path>
  url = [email protected]:foo/bar.git

and in .git/modules/<path>/config in [core] section you've the right path to your <path>, e.g.

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  worktree = ../../../<path>

If the right folder in .git/modules is missing, then you've to go to your submodule dir and try git reset HEAD --hard or git checkout master -f. If this won't help, you probably want to remove all the references to the broken submodule and add it again, then see: Rename a git submodule.

Solution 10 - Git

Scenario: changing the submodule from directory dirA-xxx to another directory dirB-xxx

  1. move the dirA-xxx to dirB-xxx

  2. modify entry in .gitmodules to use dirB-xxx

  3. modify entry in .git/config to use dirB-xxx

  4. modify .git/modules/dirA-xxx/config to reflect the correct directory

  5. modify dirA-xxx/.git to reflect the correct directory

  6. run git submodule status

    if return error: No submodule mapping found in .gitmodules for path dirA-xxx. This is due to dirA-xxx is not existing, yet it is still tracked by git. Update the git index by: git rm --cached dirA-xxx

Try with git submodule foreach git pull. I didn't go through the actual study of git submodule structure, so above steps may break something. Nonetheless going through above steps, things look good at the moment. If you have any insight or proper steps to get thing done, do share it here. :)

Solution 11 - Git

If you have:

  • removed the submodule using a simple rm instead of git rm;
  • removed the reference to the submodule in .gitmodules;
  • removed the reference in .git/config;

And you're still getting the error, what solved it for me was readding back an empty folder, where the submodule used to be. You can do this with:

mkdir -p path/to/your/submodule
touch path/to/your/submodule/.keep

.keep is just an empty file. git commit it and the error should disappear.

Solution 12 - Git

Usually, git creates a hidden directory in project's root directory (.git/)

When you're working on a CMS, its possible you install modules/plugins carrying .git/ directory with git's metadata for the specific module/plugin

Quickest solution is to find all .git directories and keep only your root git metadata directory. If you do so, git will not consider those modules as project submodules.

Solution 13 - Git

After looking at my .gitmodules, it turned out I did have an uppercase letter where I should not have. So keep in mind, the .gitmodules directories are case sensitive

Solution 14 - Git

I solved deleting the repo and running this command

git clone --recurse-submodules https://github.com/chaconinc/MainProject

It worked fine for me after that, cause none of the options here were helpful

What it does is:

  1. Clone the main repo
  2. Initialized the submodules at once right after the clone it's done

And that's it

You can find more info on this link below

Submodules

Solution 15 - Git

folder structure

xyz folder as root directory which contains 2 folder as submodule
  -- product
  -- user

execute following command from root directory

git rm --cached product/
git rm --cached user/

go to the product directory and execute

 git submodule update --init

go to the user directory and execute

git submodule update --init

go to root directory again cd ..

git add --all

Solution 16 - Git

In my case the error was probably due to an incorrect merge between .gitmodules on two branches with different submodules configurations. After taking suggestions from this forum, I solved the problem editing manually the .gitmodules file, adding the missing submodule entry is pretty easy. After that, the command git submodule update --init --recursive worked with no issues.

Solution 17 - Git

The problem for us was that duplicate submodule entries had been added into .gitmodules (probably from a merge). We searched for the path git complained about in .gitmodules and found the two identical sections. Deleting one of the sections solved the problem for us.

For what it is worth, git 1.7.1 gave the "no submodule mapping" error but git 2.13.0 didn't seem to care.

Solution 18 - Git

fatal: No url found for submodule path 'path/to/submodule' No submodule mapping found in .gitmodules for path 'path/to/submodule'

These errors began for me when I "cd" one time from my root directory folder to ./resources/css/style.css.

I used git init from style.css, recognizing my mistake after I already added git add remote origin <url>.

So, still in the style.css file in git bash, I used git remove remote origin.

When I checked git remote, the remote link had been removed.

Ultimately, after doing git init for the root directory, adding it to remote, the resources/css path was providing the submodule error/fatal errors listed up top. So, from the root directory, in git bash, I typed git rm --cached resources/css, deleted the css directory (saved the code), pushed the changes, and added a css directory and styles.css file within it in a different branch (optional) to see how the outcome would be after pushing changes again and checking the deployment on github pages. It worked! I know deleting directories isn't always ideal, especially in large projects, but just wanted to share one more way to fix this issue!

P.S fairly new to stackoverflow, so my apologies for the lengthy text. #2022 answer

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen ScheirmanView Question on Stackoverflow
Solution 1 - GitrajibchowdhuryView Answer on Stackoverflow
Solution 2 - GitVonCView Answer on Stackoverflow
Solution 3 - GitJohnnyView Answer on Stackoverflow
Solution 4 - GitluksakView Answer on Stackoverflow
Solution 5 - Gitzhuzhai liuView Answer on Stackoverflow
Solution 6 - GitJames MooreView Answer on Stackoverflow
Solution 7 - Githit9View Answer on Stackoverflow
Solution 8 - GitanomolosView Answer on Stackoverflow
Solution 9 - GitkenorbView Answer on Stackoverflow
Solution 10 - GitkenView Answer on Stackoverflow
Solution 11 - GitSimoneView Answer on Stackoverflow
Solution 12 - GityilmiView Answer on Stackoverflow
Solution 13 - GitKelseyView Answer on Stackoverflow
Solution 14 - GitJaifran HernándezView Answer on Stackoverflow
Solution 15 - Gitpiash tanjinView Answer on Stackoverflow
Solution 16 - Gituser2281802View Answer on Stackoverflow
Solution 17 - GitWalter WilfingerView Answer on Stackoverflow
Solution 18 - GitMalik SpruillView Answer on Stackoverflow