Search code examples
gitgit-submodules

Clone submodule into directory


I'm having an issue with creating a submodule in my project. If I create the submodule directly in the repository root, everything works fine. If the submodule is any deeper, the repository does not get cloned.

For example, this works as expected:

git submodule add git://someproject.com/.git someproject

However, when I run the following command, the project is added to .gitmodules and an empty repository is created, but no code is pulled down (even after a git submodule update --init). The command does not produce any output.

git submodule add git://someproject.com/.git lib/someproject

Solution

  • It appears that a previous attempt to add a submodule had left my repository in a bad state. I was able to clone the submodule correctly after performing these steps:

    1. Remove the submodule: rm -rf lib/someproject
    2. Remove the submodule from the .gitmodules file
    3. Remove the submodule from the .git/config file
    4. Remove .git/modules/someproject

    Then running the git add submodule command again worked. Many thanks to all the answerers who pushed me in the right direction!