Search code examples
iosxcodegitgit-submodules

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


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?


Solution

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