# Fill an empty submodule directory after cloning

Canonical: https://githtml.com/guides/git-submodule-directory-empty-after-clone
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

An empty submodule directory can mean the parent repository was cloned without initializing its separate submodule repositories. Inspect .gitmodules and the recorded submodule state, verify the URLs, then initialize the required paths. A normal submodule update checks out the commit recorded by the parent; updating to a remote branch tip is a different operation.

## Understand what the parent repository stores

A submodule is a separate repository referenced at a particular commit by its parent project. The parent does not simply contain all of the submodule’s source as ordinary files. Cloning the parent can therefore leave the dependency directory unpopulated until the submodule is initialized and fetched.

Read .gitmodules before contacting its URLs, especially in an unfamiliar repository. A public parent can reference a private dependency that requires separate authorization. Relative URLs also resolve according to repository context, so verify the actual destination. Do not assume a directory is a submodule merely because it is empty; inspect the recorded state rather than creating replacement files.

## Initialize the required dependency deliberately

The example scopes initialization to vendor/library. Use the real recorded path. --recursive also initializes nested submodules under that selection, which can contact additional repositories; inspect those dependencies when trust or network scope matters. Preserve changes inside an already populated submodule before updating it.

1. Check access to each referenced repository if initialization fails. Permission to the parent does not automatically grant permission to every submodule.
2. Do not add --remote just to populate the folder; that changes the selection goal toward a remote branch rather than the parent’s recorded commit.

````shell
git submodule status --recursive
git config --file .gitmodules --get-regexp 'submodule\..*\.url'
git status --short
git submodule update --init --recursive -- vendor/library
git submodule status --recursive
````

## Verify the pinned revision and project behavior

After initialization, compare the submodule’s checked-out commit with the parent’s expectation. A detached HEAD inside a submodule can be normal for this pinned checkout. If you intend to develop the dependency itself, create an appropriate branch there before making commits and coordinate how the parent reference will change.

Run the parent project’s relevant checks only after reviewing the code’s trust boundary. An initialized directory is not proof that dependencies are safe or compatible beyond the recorded version. If the required commit is unavailable upstream, ask the maintainer to restore the referenced object or update the parent deliberately. Do not silently substitute the newest dependency version merely because it downloads successfully.

1. If the parent’s status shows a submodule commit change after initialization, inspect the recorded and checked-out identifiers before staging anything. Populating a dependency should not silently become an upgrade. A previously checked-out dependency branch may differ from the commit required by the parent project.
2. For nested dependencies, identify which repository’s URL failed rather than treating the parent’s successful clone as proof of complete access. One private nested submodule can remain unavailable while its ancestors populate correctly. Request authorization for that exact dependency or ask the maintainer for the supported alternative.

## Sources and further reading

- [Git reference: git-submodule](https://git-scm.com/docs/git-submodule)
- [Git reference: git-clone](https://git-scm.com/docs/git-clone)

## Related guides

- [Move uncommitted work to the right Git branch](https://githtml.com/guides/git-uncommitted-changes-wrong-branch)
- [Undo an unpublished Git commit while keeping its edits](https://githtml.com/guides/git-undo-local-commit-keep-changes)
- [Resolve “unmerged files” before continuing Git](https://githtml.com/guides/git-unmerged-files-resolve-conflict)
- [Handle untracked files that block checkout or merge](https://githtml.com/guides/git-untracked-files-would-be-overwritten)

Editorial approach: https://githtml.com/guides/about
