Pull git submodules after cloning project from GitHub

GitGit Submodules

Git Problem Overview


I have a project that has specified submodules in it. Everything works well on the dev machine. I have commited .gitmodules file and pulled on the production. However it does not pulled submodules.

If I go into submodule directories and call git pull, nothing happens.

What is the proper way to pull those submodules in the new project ?

Git Solutions


Solution 1 - Git

From the root of the repo just run:

git submodule update --init

Solution 2 - Git

If you need to pull stuff for submodules into your submodule repositories use

git pull --recurse-submodules

But this will not checkout proper commits(the ones your master repository points to) in submodules

To checkout proper commits in your submodules you should update them after pulling using

git submodule update --recursive

Solution 3 - Git

If there are nested submodules, you will need to use:

git submodule update --init --recursive

Solution 4 - Git

I just want to share these.

First way,

git submodule init && git submodule update

The below is just basically combining the first way,

git submodule update --init

If there are any nested submodules, Iglesk's answer is the way to go.

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
QuestionhszView Question on Stackoverflow
Solution 1 - GitMatt CooperView Answer on Stackoverflow
Solution 2 - GitS. RaselView Answer on Stackoverflow
Solution 3 - GitIgleskView Answer on Stackoverflow
Solution 4 - GitmufiduView Answer on Stackoverflow