Select Page

Using SubModules

SubModules are references to other locations where code is held. These references can be private or public repositories, and are there to allow code-sharing between multiple different repos.

When to use SubModules

  • When there are several sites based on a single platform (e.g. the gallery sites).
  • When a site makes use of an external library (e.g. SwiftMailer)

Using Existing SubModules

If SubModules have already been set-up for a repo / project, they will still need to be initialised when that repo is cloned. The initialisation and update can be combined using the –init switch, and the –recursive switch means that any submodule within the configured ones will be updated as well. Run this after cloning a project, or if someone has committed changes to the submdoules:

git submodule update --init --recursive

Setting Up SubModules

To set-up a submodules, change to the directory of the repository and run:

git submodule add [repo] [target]

where [repo] is a path to a GitHub repository and [target] is the folder that it should be cloned into. There is no difference in setting up submodules from public or private repositories, except that for private ones you will be authenticated via your keys.

Make sure that submodules use the SSH address rather than HTTPS address, otherwise updates on the server cannot be automated as it would require a username and password each time.


Include the Gallery code into the folder “gallery-core/”

git submodule add [email protected]/imaginepublishing/gallery-core gallery-core

Include SwiftMailer into a folder under “vendors”

git submodule add [email protected]/swiftmailer/swiftmailer.git vendors/swift