When developing Odoo solutions, it's common to rely on external modules—whether open-source contributions, shared internal tools, or third-party plugins. Instead of manually copying these modules into your project, a cleaner and more efficient approach is to use Git submodules.
Submodules allow you to reference external Git repositories within your own project. If you're hosting your Odoo projects on Odoo.sh, submodules can help you manage dependencies more systematically and make your deployments more robust.
Why Use Submodules in Odoo.sh?
Imagine you're developing a custom Odoo module that relies on a shared library maintained in a different Git repository. Instead of duplicating that code, you can simply link it using a submodule. This gives you the benefit of:
* Cleaner project structure: Keep external dependencies separate from your core code.
* Easy updates: Pull changes from the original repository whenever needed.
* Version control: Lock a submodule to a specific commit or branch to ensure consistency.
* Automatic integration: Odoo.sh automatically recognizes submodules and includes them in the server's addons path.
Adding a Submodule via Odoo.sh Interface
If the external module is hosted in a public Git repository, Odoo.sh offers a built-in option to add it through the web interface.
Steps:
1. Go to your Odoo.sh project dashboard.

2. Open the branch where you want to add the submodule.

3. Click the Submodule button in the top-right corner.

4. Provide the following details:
* Repository URL (must be the SSH version, not HTTPS).
* Branch you want to use from that repository.
* Path within your project where the submodule should live.

5. Save your changes.
Odoo.sh will fetch the content of that repository and add it to your project structure, making it available as part of your custom modules.
* Note: This method only works for public repositories. For private ones, use the Git CLI and set up a deploy key (explained below).
Adding a Submodule Manually Using Git
If you're comfortable using Git from the command line—or need to include a private repository—you can add submodules manually.
Here's how:
1. Open a terminal and navigate to your project folder.
2. Switch to the desired branch:
git checkout your-branch
3. Run the submodule add command:
git submodule add -b branch-name git@github.com:username/repo-name.git path/to/submodule
Replace:
* branch-name with the branch of the external repo.
* git@... with the SSH URL of that repository.
* path/to/submodule with where you'd like the content to appear inside your project.
4. Commit and push the changes:
git commit -am "Added submodule"
git push origin your-branch
Now the submodule will be fetched when your code is deployed, and Odoo.sh will include its modules in your environment.
Using Private Repositories with Submodules
When adding private repositories as submodules, Odoo.sh needs permission to access them. This is done using a Deploy Key.
To set it up:
1. In your Odoo.sh project settings, go to the Submodules section.

2. Copy the Deploy Key provided by Odoo.sh.

3. In your private Git repo (e.g., on GitHub or GitLab), go to the repository settings.

4. Add the deploy key under the Deploy Keys section and allow read access.

This ensures Odoo.sh can securely fetch and integrate your private modules.
Selectively Loading Modules
If the submodule you’re adding contains multiple Odoo modules, but you only want to use a few of them, you can control what gets loaded:
1. Prefix the submodule directory with a dot (e.g., .external_addons). Odoo.sh will ignore this folder.
2. Create symbolic links from a visible addons folder to the specific modules you need.
This way, you avoid cluttering your project with unused code and have finer control over what's included in your Odoo environment.
Final Thoughts
Submodules offer a powerful way to keep your Odoo projects modular, scalable, and maintainable. Whether you're working with public or private repositories, adding them as submodules ensures you avoid redundancy and keep everything neatly versioned.
If you're working with teams or using common modules across projects, submodules are practically a must. And with Odoo.sh's automatic support for them, setting everything up is easier than ever.
To read more about How to Deploy Module in Odoo 17 Using Odoo.sh, refer to our blog How to Deploy a Module in Odoo 17 Using Odoo.sh.