Retrospectively add --recursive to a git repo

GitVersion ControlGit SubmodulesGit Clone

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Hope this helps.

Solution 2 - Git

  1. From the root of your repo:

     $ git submodule update --init --recursive
    

    That will update any and all registered submodules, initializing them if need be to the value as found in the .gitmodules file, and also recurse into complex submodules (ones with submodules of their own) and initialize and update them as well.

  2. The easiest way I know of to make cloning recursively the default would be to shadow git clone with an alias

     $ git config --global alias.clone = 'clone --recursive'
    

    As far as adding options always, I think that's the idiomatic method.

Solution 3 - Git

IIRC, git submodule init, git submodule update

Unfortunately, I do not see an option to enable recursive by default, however.

Solution 4 - Git

It appears you can't override "clone" with alias "clone", so it's a new alias (Abizern's solution) or "--recursive".

https://stackoverflow.com/questions/3538774/is-it-possible-to-override-git-command-by-git-alias

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkennethView Question on Stackoverflow
Solution 1 - GitAdam DymitrukView Answer on Stackoverflow
Solution 2 - GitTim VisherView Answer on Stackoverflow
Solution 3 - Gituser502515View Answer on Stackoverflow
Solution 4 - GitDell KronewitterView Answer on Stackoverflow