408

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?

Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137
  • 1
    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... – Cascabel Nov 15 '10 at 14:57
  • 11
    @Jefromi: http://stackoverflow.com/questions/4161022/git-how-to-track-untracked-content/4162672#4162672 ? – VonC Nov 15 '10 at 15:01
  • @Jefromi - I can find no mention of that path anywhere in the `.git` folder. Doing a `grep -r "Classes/Support/Three20" *.*` doesn't yield any results either – Ben Scheirman Nov 16 '10 at 04:36
  • 2
    @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. – Cascabel Nov 16 '10 at 04:44
  • @Jefromi - Thanks that command shed some light on the issue. Still don't know how it was introduced, but I deleted that path & then everything started working again. – Ben Scheirman Nov 18 '10 at 15:47
  • 3
    for future visitors, in case your issue is linked to a removed submodule and heroku throwing the error, install heroku-repo from https://github.com/heroku/heroku-repo and heroku repo:reset -a appname – fadomire Jun 15 '17 at 18:37
  • I've wrestled submodule problems for two days. The breakthrough came when I found this: https://forums.developer.apple.com/thread/13102. Basically, Xcode, and perhaps other apps, struggle to expand url's containing '~'. Once I changed ssh://username@server.remoteHost.com/~/git/MyRepo.git to ssh://username@server.remoteHost.com/home/username/git/MyRepo.git (look up the actual path on your server), all the weirdness disappeared with ten minutes. See also https://stackoverflow.com/questions/32833100/adding-a-github-repository-in-xcode-7-using-ssh-authentication-gives-an-authenti/33985629#33985629 – Elise van Looij Feb 09 '18 at 12:47
  • i'll add this here for future me , somehow i managed to add a submodule within a submodule for personal dotfiles repo, so printing the contents of the root `.gitmodules` did not show the sub sub module reference. ended jotting down some notes a while back that resolved my situation, https://github.com/ipatch/dotfiles/wiki/git-Notes#git-submodules- – ipatch Feb 11 '23 at 19:27
  • 1
    @ipatch Good point. I have referenced your notes in [my answer](https://stackoverflow.com/a/4185579/6309), for more visibility. – VonC Feb 11 '23 at 23:26
  • @fadomire, your answer solved the problem here; Heroku was complaining about a folder that was not in the repo for a long time, but the heroku repo:reset solved my problem – Everton J. Carpes Aug 30 '23 at 07:33

19 Answers19

492

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

KARASZI István
  • 30,900
  • 8
  • 101
  • 128
rajibchowdhury
  • 5,264
  • 2
  • 14
  • 7
  • 3
    it worked for me after having edited the .gitmodules file to change https:// links by git:// links – Diwann Jun 18 '13 at 12:24
  • 1
    This worked for me as well, but I had to be sure there was no slash at the end of the submodule path. – peter Mar 27 '14 at 16:45
  • I can not believe I forgot the init option. If you clone a project should start submodules before to update them. – alex Apr 20 '15 at 13:46
  • Had to run this in the root directory of the repo, then everything worked fine. Thanks! – Pwdr Oct 20 '15 at 20:13
  • 2
    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!. – Andrew Mar 14 '16 at 12:26
  • locate to the path/s from where said files/folder is showing error, and `git rm --cached `. Locate the parent repo, and then attempt `git submodule update --init --recursive`. It worked. – parasrish Nov 14 '16 at 06:17
  • Not working. I still cannot update a submodule. Been stuck for hours on this stupid anti-feature. – Niklas Rosencrantz Oct 22 '18 at 07:58
  • 1
    My submodules broke after a merge and this is the only thing I have found that works to fix the issue. – Fred Mar 17 '20 at 19:25
365

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, 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 .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 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: 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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 6
    I don't have any .gitmodules file and I'm still getting this message on every checkout / pull. What do i do? – aaronbauman Mar 17 '17 at 14:33
  • 2
    Found my answer here: http://stackoverflow.com/questions/14720034/no-submodule-mapping-found-in-gitmodules-for-path – aaronbauman Mar 17 '17 at 14:42
  • 5
    @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. – VonC Mar 17 '17 at 15:00
  • After running git ls-files --stage | grep 16000, i have found some entries. How do I remove these? – John Mike Nov 09 '17 at 13:57
  • 1
    @JohnMike if you have a `.gitmodule` referencing those entries, then https://stackoverflow.com/a/16162000/6309. If not, a simple `git rm afolder` (no trailing / slash) – VonC Nov 09 '17 at 13:59
  • I got stuck on this issue in a repo without any use of submodules, but after running `git add` on `new_directory` that contained a `.git` directory. The add operation failed. but the "submodule" condition stuck, so even after removing the .git directory, trying to add `new_directory` failed. Solution was `mv new_directory new_directory.save; git rm -r new_directory; mv new_directory.save new_directory`. (this was done for debugging, removing a library and copying in the source files). – hlovdal Sep 22 '22 at 11:37
  • @hlovdal Strange, I would have thought that A `git rm -r new_directory/` (with trailing slash) followed by a `git rm --cached new_directory` (no trailing slash) would have been enough to remove the folder content, and the special gitlink entry used by a submodule. – VonC Sep 22 '22 at 15:18
  • insert happy teary eye emoji – ipatch Feb 13 '23 at 00:54
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.

Johnny
  • 1,824
  • 23
  • 16
17

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]
Henrik
  • 9,714
  • 5
  • 53
  • 87
luksak
  • 3,502
  • 2
  • 25
  • 28
12

in the file .gitmodules, I replaced string

"path = thirdsrc\boost" 

with

"path = thirdsrc/boost", 

and it solved! - -

cfi
  • 10,915
  • 8
  • 57
  • 103
zhuzhai liu
  • 121
  • 1
  • 3
  • thanks fixed my problem. probably the problem that occurs in windows. In my case path was " path = something\\folder" – Roozbeh G Jan 31 '16 at 18:55
  • 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) – frage Nov 14 '18 at 00:14
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 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.

James Moore
  • 389
  • 2
  • 7
  • 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. – Xavier Poinas May 06 '15 at 16:12
7

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
hit9
  • 842
  • 8
  • 12
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... Hope this helps someone!

anomolos
  • 311
  • 3
  • 5
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 = git@github.com: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.

Community
  • 1
  • 1
kenorb
  • 155,785
  • 88
  • 678
  • 743
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
Tanjin Alam
  • 1,728
  • 13
  • 15
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. :)

ken
  • 13,869
  • 6
  • 42
  • 36
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.

Simone
  • 20,302
  • 14
  • 79
  • 103
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.

yilmi
  • 162
  • 5
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

Kelsey
  • 541
  • 3
  • 11
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

  • 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](/help/how-to-answer). – Community Oct 15 '21 at 05:19
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!

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

  • 2
    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. – rjmAmaro Feb 23 '22 at 23:29
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.

user2281802
  • 231
  • 2
  • 2
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.

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]

Zhou Haibo
  • 1,681
  • 1
  • 12
  • 32