Really, what is the difference between submodule add and submodule init? Or more precisely when would you want to use one without the other?
You use git submodule add when you yourself want to add a new submodule to a project.
You use git submodule init when you clone a project that has submodules, or when someone else has added a submodule to a project.
Add is when you want to import another git repository to your current git repository (called the "superproject"). To perform that it records in the .gitmodules the path to the repository, thus adding it to the index.
Submodule init will create already-existing submodules recorded in the index. This is achieved configuring the paths found in the index in git.
Add:
Add the given repository as a submodule at the given path to the changeset to be committed next to the current project: the current project is termed the "superproject".
Init:
Initialize the submodules recorded in the index (which were added and committed elsewhere) by copying submodule names and urls from
.gitmodulesto.git/config.
Therefore init checks out the submodules already recorded in the index that where previously added with
git submodule add my_sub_project directory_in_superproject
Typically when cloning the superproject you would do:
git clone superproj
within the project then:
git submodule update --init
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With