Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 252
kenneth Avatar asked Nov 23 '10 01:11

kenneth


People also ask

How do I add a submodule to a git repository?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

How do I clone a recursive repository?

You can use the --recursive flag when cloning a repository. This parameter forces git to clone all defined submodules in the repository.

What does recursively clone submodules mean?

git clone(1) --recursive. Clone a repository into a new directory. --recursive, --recurse-submodules After the clone is created, initialize all submodules within, using their default settings. This is equivalent to running git submodule update --init --recursive immediately after the clone is finished.

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.


2 Answers

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.

like image 83
Adam Dymitruk Avatar answered Sep 24 '22 14:09

Adam Dymitruk


  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.

like image 36
Tim Visher Avatar answered Sep 23 '22 14:09

Tim Visher