Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "git clone" including submodules?

I'm trying to put a submodule into a repo. The problem is that when I clone the parent repo, the submodule folder is entirely empty.

Is there any way to make it so that git clone parent_repo actually puts data in the submodule folder?

For example, http://github.com/cwolves/sequelize/tree/master/lib/, nodejs-mysql-native is pointing at an external git submodule, but when I checkout the sequelize project, that folder is empty.

like image 613
Nobody Avatar asked Sep 26 '10 07:09

Nobody


People also ask

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.

How do I combine submodules?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

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 does git pull -- recurse submodules do?

git submodule foreach git pull origin master or git pull origin master --recurse-submodules is what you want if you intend to update each submodule to the latest from their origin repositories. Only then will you get pending changes in the parent repo with updated revision hashes for submodules.


2 Answers

With version 2.13 of Git and later, --recurse-submodules can be used instead of --recursive:

git clone --recurse-submodules -j8 git://github.com/foo/bar.git cd bar 

Editor’s note: -j8 is an optional performance optimization that became available in version 2.8, and fetches up to 8 submodules at a time in parallel — see man git-clone.

With version 1.9 of Git up until version 2.12 (-j flag only available in version 2.8+):

git clone --recursive -j8 git://github.com/foo/bar.git cd bar 

With version 1.6.5 of Git and later, you can use:

git clone --recursive git://github.com/foo/bar.git cd bar 

For already cloned repos, or older Git versions, use:

git clone git://github.com/foo/bar.git cd bar git submodule update --init --recursive 
like image 131
Mathias Bynens Avatar answered Oct 04 '22 15:10

Mathias Bynens


You have to do two things before a submodule will be filled:

git submodule init  git submodule update 
like image 41
LiraNuna Avatar answered Oct 04 '22 15:10

LiraNuna