Skip to content
Versora

Manual

Repository

Submodules

7 min read

On this page

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.

The SUBMODULES section

Each row shows the submodule's folder and a state mark:

MarkStateWhat it means
✓up to dateOn the recorded commit, with no changes (tooltip: "Up to date: on the recorded commit, with no changes").
not initializednot initializedIt hasn't been downloaded to this computer yet.
↓N / ↑Non a different commit than recordedThe submodule is N commits behind (↓) or ahead of (↑) the recorded one.
other commiton a different commit than recordedIt's on a commit that isn't the recorded one, neither behind nor ahead of it.
● and modifiedhas local changesIt has uncommitted changes inside the submodule.
conflictconflictedThe 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."

Adding a submodule

Where to find it

  • + button in the SUBMODULES section header (tooltip "Add submodule").

Step by step

  1. 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."
  2. In Repository URL, paste the URL (https://… or git@…).
  3. 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.
  4. In Branch to track (optional), enter the branch the submodule follows. Left empty, the remote default applies.
  5. Click Add submodule.
  6. The notice says "Submodule ‹folder› added. The submodule and .gitmodules are already staged for the commit." Commit to record the submodule in the repository.
OptionWhat it doesDefault
Repository URLRepository to clone inside this one.Required
Folder inside this repositoryPath 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

What Versora does in git

bash
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.

Caveats and messages

  • "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.

Opening and initializing a submodule

Where to find it

  • Double-click the submodule, or Open in a tab in its menu.
  • Initialize in the menu of a submodule that isn't initialized.

Step by step

  1. Double-click the submodule.
  2. 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.
  3. 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.

What Versora does in git

bash
git submodule update --init -- libs/componentes

Updating a submodule

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.

Where to find it

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)").

Step by step

  1. Right-click the submodule and choose the update.
  2. 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.
  3. 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.").
ItemCommand
Update to the recorded commitgit submodule update --init -- <folder>
Update to the latest from the remotegit submodule update --init --remote -- <folder>
Update allgit 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.

Syncing and editing the URL

Where to find it

Right-click the submodule: Sync URL, Edit URL… and Copy URL ("URL copied").

Step by step

  • Sync URL: copies the URL from .gitmodules to 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.

What Versora does in git

bash
git submodule sync -- libs/componentes
git submodule set-url -- libs/componentes https://exemplo.com/nova/componentes.git

Other menu items

  • Copy path: copies the submodule's full folder path ("Path copied").
  • Show in file explorer: opens the folder in File Explorer.

Removing a submodule

Where to find it

Right-click the submodule: Remove submodule…

Step by step

  1. 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 .gitmodules and from the index, and the removal is staged for the next commit. The remote repository isn't affected.
  2. 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."
  3. Click Remove submodule.
  4. Commit to record the removal.

What Versora does in git

bash
# 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

Caveats and messages

  • "The .gitmodules file has unstaged changes. Stage or discard them before removing the submodule.": git rm needs 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).

The diff of a submodule

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."

How to undo

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 .gitmodules and of the folder in the changes panel (see Discarding changes). Since the folder and the clone in .git/modules were 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.

See also