Submodules

Git provides submodules to use another project in your repository1. This is a handy way to separate content and apply different access rights. For example, if you want to create a hidden area for a treasure hunt like me. I use a private repo from within my main Website repo. If you view the sources of the Influenca page in this repo and want to access the folder hidden @ <hash>, you’ll get a 404 page as this is a link to the private repo. Only authenticated users can access it.

Enabling auto-update

To automatically update submodules on git clone and git pull I enable submodule.rescurse:

git config submodule.recurse true

Adding into main

The command to add a submodule expects the destination of the other project and a relative path inside the main repository. For example, to add the repo https://codeberg.org/thisven/private as submodule into content/blog/hidden the command would be:

git submodule add https://codeberg.org/thisven/private content/blog/hidden

Additionally, a .gitmodules file is created to maintain the submodule details:

.gitmodules
[submodule "content/blog/hidden"]
    path = content/blog/hidden
    url = https://codeberg.org/thisven/private

Pulling from remote

If you have cloned a repo before enabling auto-update, you can manually pull from the submodule repo using this command:

git submodule update --remote

If you are cloning an existing main repo that contains submodules, you can use git clone with the --recurse-submodules option.


  1. Software repository in the Wikipedia ↩︎

Last updated on