2

I have added the Xcode project into the git repo. When I run the following command:

$ git submodule init

I get the following error:

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

I didn't add the 'Pods' submodules, it is added on its own?

Adham Enaya
  • 780
  • 1
  • 11
  • 29

2 Answers2

13

Not sure why Pods is listed in your .gitmodules. This article mentions

This occurs when the repository is using files cloned from another repository but has had no mapping reference to the source repository created for it.

The mapping needs to be added to a .gitmodules file located in the root directory of the repository you are using.

But in your case, edit the .gitmodules file and remove the Pods entry.

And check if there is any Pods entry in your index:

git rm --cached -- Pods

That will remove the gitlink, a SHA1 recorded as a special entry in the index.
That will be enough to remove trace of the submodule.


This answer (in its original form) could be construed as "useless and misleading many people" because of:

  • Lack of Explanation
  • Assumes Pods Should Not Be a Submodule:
  • Potential Unwanted Consequences

I could rephrase said answer as:

While it is unusual to see the 'Pods' directory listed in your .gitmodules file if you have not added it as a submodule, there are a few scenarios where this could occur. Before we proceed with the solution, let's understand what's happening here.

This error typically occurs when the repository is using files cloned from another repository but has had no mapping reference to the source repository created for it. The mapping needs to be added to a .gitmodules file located in the root directory of the repository you are using.

In this case, there seems to be an entry for 'Pods' in your .gitmodules file, and your Git repository is looking for a corresponding URL to fetch the submodule content but cannot find one. This could be due to a manual addition or some tooling in your development environment adding it.

Before taking any action, please ensure that the 'Pods' directory is not intended to be a submodule. If you are using CocoaPods, for instance, some developers prefer to keep the 'Pods' directory in source control, while others prefer not to. If you are certain that 'Pods' should not be a submodule, then you can proceed with the following steps.

First, edit the .gitmodules file and remove the 'Pods' entry. This will stop Git from trying to find a URL for the 'Pods' submodule.

Then, check if there is any 'Pods' entry in your index by running this command:

git rm --cached -- Pods

This command removes the gitlink (a special entry in the index) for 'Pods', which is essentially a reference to the commit in the submodule.

Do note these actions have potential consequences. If 'Pods' was meant to be a submodule, these steps could cause issues in your project. Always ensure to have a backup of your project or ensure your changes are pushed to a remote repository before performing these operations.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

Giving a slightly more technical answer for more general problems which have the same error message.

A git submodules consists of:

  1. A committed commit stored in the git index at a particular path (you can see these as commit objects when you run git ls-tree HEAD as described here)
  2. An entry in the .gitmodules (which is committed) file for this path containing a url from which to get this commit.
  3. An entry in .git/config (which is not committed) keeping track of what is actually checked out and changed to it.

Needless to say, this is a little confusing and I suspect the world would be simpler if they had elected to not keep the commit

This error means that there is a commit with no corresponding entry in .gitmodules, the fix is to either remove the commit object or add the entry to .gitmodules.

Att Righ
  • 1,439
  • 1
  • 16
  • 29