Submodule

Separate repositories.

Will not auto update - as part of parent repo.

Will have to be managed separately.

No separate .git directory.

Git data in parent .git/modules/<name> directory

Instead only a .git file

That links back to the parent git directories' submodule git data directory.

.gitmodule file.

*Path should match in / style too

Hence use unix style paths only /.

Contains records for submodules.

Recursive submodules.

.git data stored in respective parent .git\modules directory.

Run following to pull child submodules recursively.

git submodule update --init --recursive

-.

Prepare remote separately.

And then pull into current parent .git project.

git submodule add --name <name> <url> [path]

Url:

For example, file:///d//Store.

name. Is the title.

It goes with .git/modules/<name> directory

path. Goes in working directory.

Can be - relative to current directory (must begin with ./) or absolute.

Adds .gitmodules file at root.

The directory name though still is the git target’s name

This has to be renamed manually if required

Path reference has to be updated in .gitmodules as well.

DO NOT rename directories manually. Use the path and name params instead.

Should show up as a already staged entry in git status

Content will be “Subproject commit <hash>”

Git uninit.

deinit

deinit git submodule deinit -f <submodule:name>
deinit May not remove the .git\modules\<name> directory

May not remove entry from .gitmodules file.

Will not remove <name> directory from working directory, will probably be left empty

Add from console separately post submodule add.

An object with only the repo hash will be created.

Additional steps (legacy).

https://stackoverflow.com/a/16162000/483588

  1. mv a/submodule a/submodule_tmp.
1. git submodule deinit -f -- <a/submodule>
2. rm -rf .git/modules/a/submodule
3. git rm -f a/submodule

# Note. A/submodule (no trailing slash).

Edit the .gitmodule file.

or, if you want to leave it in your working tree and have done step 0.

3.   git rm --cached a/submodule

3bis mv a/submodule_tmp a/submodule.

Add submodule directory to index

Git submodule add -- will add existing repo to index if rest is fine.

git ls-files

Shows files in index.

git submodule update --init --recursive

Fetches nested submodules.

Updated: 2026 Aug 19