Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

Using git Submodules

David Egan

Submodules are a way of including third-party git repos in a project. For example, the TCPDF library might be included as a submodule in the repo of a WordPress theme.

Adding a Submodule

Add an existing git repository as a submodule:

git submodule add

The submodule is added by default to a directory with the same name as the repo - in this case “CMB2”.

Clone With Submodules

To clone a project with submodules, use the recursive option:

git clone --recursive <url of repo>

Retrospectively Add Submodules

You can also clone submodules as a second step - this may be necessary if you have already cloned the repo:

git clone <repo>
cd <repo>
git submodule init
git submodule update

# To update submodule, add an extra step after running git pull
git pull origin master
git submodule update --recursive

You can create and switch to a new branch, which allows you to work without affecting the production code. Once happy wit changes, the branch can be merged back and deployed.


If you’re using this to deploy code onto a remote server, remember that you may need an SSH key pair connection to the remote repo (e.g. GitHub).


comments powered by Disqus