442

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?

12
  • 2
    It sounds like you might've managed to add that path as a gitlink - a submodule is a combination of a gitlink and entries in the .gitmoddules and .git/config files. There was a recent question about this; trying to find it... Commented Nov 15, 2010 at 14:57
  • 12
    @Jefromi: stackoverflow.com/questions/4161022/… ? Commented Nov 15, 2010 at 15:01
  • 3
    @Ben: Why are you searching for that text in the .git folder? That's not how git stores content. If you really want to verify what git thinks it is, try git ls-tree HEAD Classes/Support, and if it says Three20 is a commit, there's a gitlink there. If there is, follow the appropriate instructions from the question VonC linked above to either turn it into a proper submodule or turn it into regularly tracked content. Commented Nov 16, 2010 at 4:44
  • 4
    for future visitors, in case your issue is linked to a removed submodule and heroku throwing the error, install heroku-repo from github.com/heroku/heroku-repo and heroku repo:reset -a appname Commented Jun 15, 2017 at 18:37
  • 1
    @ipatch Good point. I have referenced your notes in my answer, for more visibility. Commented Feb 11, 2023 at 23:26

20 Answers 20

534

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

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

5 Comments

it worked for me after having edited the .gitmodules file to change https:// links by git:// links
This worked for me as well, but I had to be sure there was no slash at the end of the submodule path.
Had to run this in the root directory of the repo, then everything worked fine. Thanks!
Thank you very much for rm command. I called git submodule sync | grep "mapping found" then git rm and again git submodule sync. Problem gone away!.
locate to the path/s from where said files/folder is showing error, and git rm --cached <file_path>. Locate the parent repo, and then attempt git submodule update --init --recursive. It worked.
390

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 .gitmodules (like 'Classes/Support/Three20' in the original question), then you need to remove it 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 .gitmodules 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 resolves 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 on the topic of "incorrect submodule initialization", Jefromi mentions submodules which actually are gitlinks.

See "How to track untracked content?" to convert such a directory to a real submodule: as commented by ipatch, and details in ipatch's notes:

If you run into the below error when working git submodules

mr-fancy-42-repo already exists in the index 
  1. Remove the submodule folder / directory
  2. Remove the git cache for the folder / directory
  3. Then reinitialize submodule
rm -Rf /path/to/mr-fancy-42-repo git rm -R /path/to/mr-fancy-42-repo git submodule add [mr-fancy-42-submodule-repo] /path/to/initialize/submodule/repo 

Luke Schoen's comment illustrates that adding a submodule using an absolute path (like ~/nunya/packages/relayer) will make Git register it incorrectly in the index or .git/config: .gitmodules expects a relative path (e.g., packages/relayer).
That mismatch can lead to the "no submodule mapping found…" error.

To summarize: stale submodule references can remain in:

  1. .git/config: Blocks named [submodule "packages/relayer"] that point to the wrong path.
  2. Index: If a path was added as a submodule (mode 160000) but is not in .gitmodules.

A quick fix is to:

  • remove (git rm --cached) the stale submodule entry,
  • make sure the path in .gitmodules matches how you run git submodule add, and
  • re-add the submodule with the correct relative path (which Luke did).

8 Comments

I don't have any .gitmodules file and I'm still getting this message on every checkout / pull. What do i do?
@aaronbauman Yes, you need to remove the gitlink, hence the git rm xxx (without trailing slash) git rm --cached allows you to keep it on disk while removing it from the index.
After running git ls-files --stage | grep 16000, i have found some entries. How do I remove these?
@JohnMike if you have a .gitmodule referencing those entries, then stackoverflow.com/a/16162000/6309. If not, a simple git rm afolder (no trailing / slash)
|
26

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.

Comments

18

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] 

Comments

13

in the file .gitmodules, I replaced string

"path = thirdsrc\boost" 

with

"path = thirdsrc/boost", 

and it solved! - -

2 Comments

thanks fixed my problem. probably the problem that occurs in windows. In my case path was " path = something\\folder"
This worked for me when i hit an error when using git-lfs instead of git on windows. (No error occurred when using standard git)
10

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 [email protected]: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.

1 Comment

Same here (Windows), although I don't understand why. You should be free to specify a folder with different casing for the checkout and this shouldn't change the module name.
7

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

Comments

5

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.

Comments

5

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...

Comments

4

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 

Comments

3

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. :)

Comments

2

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.

Comments

2

In my case this was happening because i have having multiple submodule's

so i need to add them all manually in .gitmodules, here's how updated .gitmodules look's

[submodule "module1"] path = module1 url = https://github.com/kalilinux-png/module1.git [submodule "module2"] path = module2 url = https://github.com/kalilinux-png/module2.git [submodule "module3"] path = module3 url = https://github.com/kalilinux-png/module3.git 

Comments

1

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.

Comments

1

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

Comments

1

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1
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!

1 Comment

Hi @Malik. It looks like your answer is similar to an existing one. If you consider your answer to be different, maybe you can try to improve it and shed some light on the difference.
0

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.

Comments

0

In my case, I move .gitmodules file to root dir solve the problem, I take me half an hour to figure out it...

Root Dir Dir Dir Dir Submodule repo files .gitmodules [Wrong place] 
Root Dir Dir Dir Dir Submodule repo files .gitmodules [Correct] 

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.