Clone from gitmodules

Clone from gitmodules

Table of contents

No heading

No headings in the article.

When cloning a repository that contains submodules, you need to use the --recursive flag to clone the main repository as well as all of its submodules. Here's how to clone a repository and its submodules:

  1. Open your terminal and navigate to the directory where you want to clone the repository.

  2. Clone the main repository using the git clone command and include the --recursive flag to clone submodules along with the main repository:

git clone --recursive <repository URL>

For example, if you're cloning a repository named "my_project" from GitHub, the command would look like this:

git clone --recursive
  1. Alternatively, if you have already cloned the repository but did not include the --recursive flag, you can still clone the submodules by navigating to the repository directory and running the command:
git submodule update --init --recursive

This command initializes any submodules that have been added to the repository since it was cloned, and updates any existing submodules to match their respective upstream branches.

Once you've cloned the repository and its submodules, you can work with them just like any other Git repository. Note that any changes made to a submodule require a separate commit and push to update the submodule repository.

PS: To ensure that every submodules get cloned in projects you work on, you may set this command globally:

git config --global submodule.recurse true

When enabled, this parameter instructs git to automatically clone all submodules within the repository and register them as remotes in the local copy. This can be useful when dealing with Git repositories which contain both the code and its submodules, and can save time since the user doesn't need to manually clone each submodule.