GitHub Tricks - Submodule

November 10, 2017


I have been working with many project on GitHub recently. One thing that I have learned is the use of git submodules. I am borrowing an example from Git Tools - Submodules, where you can see adding submodules into the repository is really easy:


$ git submodule add https://github.com/chaconinc/DbConnector

Cloning into 'DbConnector'...

remote: Counting objects: 11, done.

remote: Compressing objects: 100% (10/10), done.

remote: Total 11 (delta 0), reused 11 (delta 0)

Unpacking objects: 100% (11/11), done.

Checking connectivity... done.


This will create a file called .gitmodules and you will have to commit it onto the repository.


After you have cloned the repository somewhere, it is also easy to populate the submodule directories, using:

$ git submodule init

$ git submodule update


An example use of the submodules can be seen in one of my GitHub projects.