2

Switching branches (using SourceTree), I get error messages like

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

There is no .gitmodules file in the whole project.

Where should I look at?

SourceTree hits the following command upon branch switching:

git --no-optional-locks -c core.quotepath=false submodule update --init 

When I enter git submodules, the output is:

# git submodule                        
fatal: no submodule mapping found in .gitmodules for path '...'

Folder ... is empty.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151

1 Answers1

4

What you have here is a broken submodule. (Or half a submodule? A submodule without instructions? It's not clear just what to call it—other than, as VonC notes, we can say that the gitlink half is a "gitlink", which at least is a searchable jargon term.)

A submodule, in Git, is a reference to another Git repository. In order to use the submodule, you must already have the other Git repository. In general, to make a Git repository, we mostly use git clone to copy some other, existing, repository. So normally, a submodule carries along with it the necessary instructions that Git will need in order to run git clone. These instructions go into the .gitmodules file.

If the .gitmodules file is missing, as in this case, it means that the instructions for setting up the submodule are missing. It's up to you whether to repair this by adding the instructions, or to repair it by removing the badly-formed submodule from your next commit.

Removing the half-formed submodule is easier. See VonC's accepted answer to No submodule mapping found in .gitmodule for a path that's not a submodule, but all you have to do is use git rm and then commit. This new commit will no longer refer to the submodule that cannot be cloned because the cloning instructions are missing. Subsequent new commits, built from this commit that doesn't mention the submodule, also won't mention the submodule (which continues to not exist).

Note that all existing commits remain broken. The only thing you can do about this is to remove (or replace) any existing broken commits, because no existing commit can be modified. It's generally not a great idea to try to fix or remove existing commits, as other people may be depending on them. A half-submodule / broken-submodule like this can be worked-with as a regular (non-broken) submodule if you have the other Git repository cloned into place.

To fix the problem by fixing the submodule, put the appropriate configuration into a new .gitmodules file and git add and git commit the .gitmodules file. The problem with actually doing this, of course, is that you need to know what the instructions are. Some of them are clear from the broken submodule, because the information in the .gitmodules file comes in several parts: one part is the path, which is just the name of the mode-160000 git ls-files entry (again, see VonC's answer). But the other part is the URL for the repository that should be cloned, and who knows what that might be?1


1In theory, whoever owns whichever repository you cloned to get into this situation should know—or, they should know who knows, or know someone who knows someone who knows, etc. But in practice, you get a lot of It was like that when I got here.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Regarding your footnote: I'm working by the rule of `origin/master` precedence. Whats not working in that branch, will not be missed anywhere. – Daniel W. Jan 07 '20 at 19:36
  • It is clear what to call it: a nested Git repository stored as a gitlink tree entry, as explained https://www.git-scm.com/docs/gitsubmodules. – VonC Jan 08 '20 at 07:21
  • @VonC: but that calls out four forms of submodule, all of which have a `.gitmodules` file. In this case there is a gitlink but no `.gitmodules` file. What is the correct name for this fifth form? (Note that the OP has no second Git repository either, just an empty folder where Git expects to find something.) – torek Jan 08 '20 at 07:35
  • @torek I meant: a nested git repo without a .gitmodule is just a gitlink (a special entry in the index). – VonC Jan 08 '20 at 07:57
  • When I removed the empty folder, the message in git history was this: `Deleted file: Subproject commit 39747efdc1ff781939c45f321475f00f71ef3172`. All what you both point out makes sense. – Daniel W. Jan 08 '20 at 11:45