Skip to main content
Submodules let you include other repositories inside your project while keeping them separate.

Overview

Use submodules when you need to:
  • Include a library as a subdirectory
  • Share code between projects
  • Pin external dependencies to specific versions
  • Keep separate repositories for components

Commands

Add Submodule

Example:
This:
  1. Clones the repository to vendor/utils
  2. Records the submodule in .witmodules
  3. Stages the changes

Initialize Submodules

After cloning a repo with submodules:
This registers submodules from .witmodules.

Update Submodules

Fetch and checkout the recorded commits for all submodules. Combined initialize and update:

Status

Output:

Run Command in Submodules

Examples:

Configuration File

Submodules are recorded in .witmodules:

Workflow

Adding a Submodule

Cloning a Repo with Submodules

Updating a Submodule

Removing a Submodule

Directory Structure

Use Cases

Shared Libraries

Pinned Dependencies

Multi-repo Project

Best Practices

Always commit submodule updatesWhen you update a submodule, commit the change to the parent:
Use branches for trackingIn .witmodules, specify a branch:
Be careful with submodule changesChanges inside a submodule must be committed there first, then recorded in the parent.

Troubleshooting

Run init and update:
Either commit them in the submodule:
Or discard:
Ensure you have push access to the submodule’s repository, then push from within the submodule: