Search code examples
gitversion-controlgit-submodulesgit-clone

Retrospectively add --recursive to a git repo


If you git clone with --recursive, you can get all the git submodules too.

If I've forgotten to add this magical flag when cloning, as can happen, how do I now go and get any submodules?

Additionally, how can I set the recursive flag as a default for future clones?


Solution

  • You can do it with this after a simple top-level clone:

    git submodule update --init --recursive
    

    I would not recommend making clone do this by default. The proper way to do this if you are using submodules aggressively for development and not just linking to 3rd party OSS libs on github that you may upgrade once in a blue moon, is to use git slave or subtree.