Repository
Submodules
7 min read
A submodule is another repository kept inside this one, in its own folder. The parent
repository doesn't store the submodule's files: it stores only the URL (in .gitmodules) and the
recorded commit, the exact submodule commit this repository uses. Whoever clones the parent
needs to initialize the submodule to download its content.
Versora shows the submodules in the SUBMODULES section of the left panel, with the state of each one, and opens any submodule in a tab like a regular repository.
Each row shows the submodule's folder and a state mark:
| Mark | State | What it means |
|---|---|---|
| ✓ | up to date | On the recorded commit, with no changes (tooltip: "Up to date: on the recorded commit, with no changes"). |
| not initialized | not initialized | It hasn't been downloaded to this computer yet. |
| ↓N / ↑N | on a different commit than recorded | The submodule is N commits behind (↓) or ahead of (↑) the recorded one. |
| other commit | on a different commit than recorded | It's on a commit that isn't the recorded one, neither behind nor ahead of it. |
| ● and modified | has local changes | It has uncommitted changes inside the submodule. |
| conflict | conflicted | The recorded commit is conflicted in a merge or rebase of the parent. |
Hover to see the tracked branch, the recorded commit, the current commit and the state. Double-clicking opens the submodule in a tab (and, if it hasn't been initialized, offers to initialize it first). With no submodules, the section shows "No submodules. Use + to add one."
- + button in the SUBMODULES section header (tooltip "Add submodule").
- Click +. The Add submodule window explains: "Clones another repository inside this one, in its own folder. The parent repository stores only the URL and the commit in use."
- In Repository URL, paste the URL (
https://…orgit@…). - In Folder inside this repository, choose where it goes. Left empty, it goes to the root,
with the repository name. For another folder, type for example
libs/componentes. - In Branch to track (optional), enter the branch the submodule follows. Left empty, the remote default applies.
- Click Add submodule.
- The notice says "Submodule ‹folder› added. The submodule and .gitmodules are already staged for the commit." Commit to record the submodule in the repository.
| Option | What it does | Default |
|---|---|---|
| Repository URL | Repository to clone inside this one. | Required |
| Folder inside this repository | Path of the submodule, relative to the root. | The repository name, at the root |
| Branch to track (optional) | Writes the branch to .gitmodules (used by "Update to the latest from the remote"). | Remote default |
git submodule add -b main -- https://exemplo.com/equipe/componentes.git libs/componentes
Git clones the repository into the folder, writes the entry to .gitmodules and stages both. When
the URL is a folder on this computer, the app allows the file protocol only for that command
(-c protocol.file.allow=always), because you're the one who typed the path.
- "Enter the submodule URL."
- "The folder "‹folder›" already exists and isn't empty.": choose another folder.
- "For security, Git blocks submodules whose URL is a local path on this computer (protocol.file.allow)…": appears in operations that clone a submodule with a local URL (for example, when initializing). The message includes the command to allow it, if you trust the repository.
- Double-click the submodule, or Open in a tab in its menu.
- Initialize in the menu of a submodule that isn't initialized.
- Double-click the submodule.
- If it hasn't been downloaded, the Submodule not initialized window says that initializing "clones ‹url› and checks out the recorded commit (‹sha›)". Click Initialize and open.
- The submodule opens in a tab. The repository bar shows "Submodule of ‹parent›" and the Back to ‹parent› button, which goes back to the parent repository's tab.
git submodule update --init -- libs/componentes
The commit recorded in the parent and the commit checked out in the submodule can drift apart: you made commits inside the submodule, someone changed the recorded commit in a pull, or the submodule fell behind. The menu has two updates.
Right-click the submodule:
- Update to the recorded commit (‹sha›): moves the submodule to the commit the parent records;
- Update to the latest from the remote: fetches from the submodule's remote and moves to the latest commit of the tracked branch.
And in the section header, the update all button (tooltip "Update all (initializes each submodule and moves it to the recorded commit, including nested ones)").
- Right-click the submodule and choose the update.
- If the submodule is ahead of the recorded one, the Update ‹folder› window warns that it will move to the recorded commit in detached HEAD. The extra commits stay on the branch where they were made; if they were made in detached HEAD, they can only be brought back from the submodule's reflog. Click Go back to the recorded commit to continue.
- After "Update to the latest from the remote", if the commit changed, the submodule change shows up in the parent's changes panel for you to stage and commit ("‹folder› updated from the remote. If the commit changed, the submodule change shows up to be staged and committed.").
| Item | Command |
|---|---|
| Update to the recorded commit | git submodule update --init -- <folder> |
| Update to the latest from the remote | git submodule update --init --remote -- <folder> |
| Update all | git submodule update --init --recursive |
Both updates are disabled for a conflicted submodule.
Caution
Updating to the recorded commit takes the submodule off the branch it was on and leaves it in detached HEAD. If you committed inside the submodule in detached HEAD, create a branch there first, or those commits are only reachable from the submodule's reflog.
Right-click the submodule: Sync URL, Edit URL… and Copy URL ("URL copied").
- Sync URL: copies the URL from
.gitmodulesto the local configuration and to the submodule's remote. Use it after a pull that changed the URL in.gitmodules("URL of ‹folder› synced with .gitmodules"). - Edit URL…: the URL of ‹folder› window explains: "The new URL is written to .gitmodules (a
change to commit) and applied to the local configuration and to the submodule's remote." Type the
URL and click Save URL. Then commit
.gitmodules.
git submodule sync -- libs/componentes
git submodule set-url -- libs/componentes https://exemplo.com/nova/componentes.git
- Copy path: copies the submodule's full folder path ("Path copied").
- Show in file explorer: opens the folder in File Explorer.
Right-click the submodule: Remove submodule…
- Choose Remove submodule…. The Remove submodule ‹folder› window says what will be deleted
from this computer: the folder with everything in it and the clone kept in
.git/modules/<name>. The entry is removed from.gitmodulesand from the index, and the removal is staged for the next commit. The remote repository isn't affected. - If the submodule has local changes or commits beyond the recorded one, the window warns: "WARNING: this submodule has ‹risks› — all of it will be lost and can't be recovered from here."
- Click Remove submodule.
- Commit to record the removal.
# only in the old format, with the repository inside the submodule's own folder
git submodule absorbgitdirs -- libs/componentes
git submodule deinit -f -- libs/componentes
git rm -f -q -- libs/componentes
# and deletes .git/modules/<name>, so a new submodule with the same name doesn't reuse the old one
- "The .gitmodules file has unstaged changes. Stage or discard them before removing the
submodule.":
git rmneeds to rewrite.gitmodules. - ""‹folder›" isn't a submodule declared in .gitmodules."
- "The submodule was removed from the repository, but ‹folder› couldn't be deleted: ‹error›": delete the folder manually (some program may have it open).
When the recorded commit changes, the submodule appears in the changes panel as a file with the sub badge ("Submodule: what changes here is the recorded commit"). When you open it, the diff doesn't show lines: it shows the change of commit.
- "Submodule on another commit", "Submodule added", "Submodule removed" or "Submodule with local changes", with the commit before and the one after;
- how many commits come in and go out (+N / −N), with the Incoming commits and Outgoing commits lists;
- the Stage submodule (or Unstage), Open the submodule in a tab, Initialize (when it hasn't been downloaded) and Go back to the recorded commit buttons (unstaged, with the submodule on a different commit; tooltip "Checks out, inside the submodule, the commit recorded in this repository").
Uncommitted changes inside the submodule don't go into the parent's commit: "There are uncommitted changes inside the submodule. They don't go into this repository's commit: open the submodule, commit there, and then stage the new recorded commit here."
Submodule operations don't change the parent repository's branches, tags or HEAD, so they aren't part of Ctrl+Z. To go back:
- an addition not yet committed: remove the submodule with Remove submodule…;
- a removal not yet committed: discard the removal of
.gitmodulesand of the folder in the changes panel (see Discarding changes). Since the folder and the clone in.git/moduleswere deleted, the submodule comes back as "not initialized" and needs to be initialized again; - an update: use the opposite update, or open the submodule and check out the commit you want.
There's no setting of its own. Cloning with Also clone submodules (--recurse-submodules) is
in the clone's advanced options: see Shallow clone and partial clone.
- Repository: overview
- Open, clone and create repositories
- Official documentation: git submodule (opens another site)