What is a subproject commit in Git?
Codemia Knowledge Hub ·
A "subproject commit" is the exact submodule commit recorded by a parent Git repository. The parent does not store the submodule's history; it stores a pointer to one specific child commit, so every clone reproduces the same dependency state.
What the parent repository tracks
A submodule is its own repository nested inside another. The parent keeps two pieces of information:
- the submodule URL in
.gitmodules - the exact checked-out child commit in the Git index
The second one is the subproject commit. It is not "latest on main" and not a semantic version; it is one exact commit hash from the child repository.
After this commit, the parent is saying "use this repository at this exact revision."
Why Git stores a commit, not a branch
Branches move; commits do not. If the parent tracked a branch name, two developers cloning the same parent commit on different days could get different dependency code. A commit hash makes the state reproducible, which matters for:
- CI consistency
- release rebuilds
- debugging old production versions
- stable collaboration across machines
So submodules behave like pinned snapshots, not floating dependencies.
How the pointer changes
Suppose you update the submodule itself:
The parent now sees that vendor/shared-lib points at a different child commit, but nothing is recorded until you stage and commit the changed pointer:
The workflow always has two layers:
- commit in the submodule if the child code changed
- commit in the parent to record the new subproject commit
Checking out the recorded commits after clone or pull
After cloning the parent, initialize the submodules at the recorded commits:
After pulling parent changes, the same command moves submodules to the commits the parent now expects:
Detached HEAD is expected
Because Git checks out the precise recorded commit rather than a branch tip, a submodule usually sits in detached HEAD. That is normal, not a bug. To edit the submodule, switch to a branch first:
Commit your changes there, return to the parent, and commit the updated pointer.
Why teams use subproject commits
They give controlled reproducibility: "this build uses that dependency at exactly this revision." That is useful when the child repo is internal, not published through a package manager, or developed alongside the parent. The cost is workflow overhead, since updating the dependency always means committing the parent pointer too.
Mistakes to avoid
- Committing inside the submodule and forgetting to commit the new pointer in the parent.
- Assuming
git pullin the parent updates every submodule's working tree. - Treating detached HEAD in a submodule as an error.
- Committing in a detached HEAD submodule and losing track of where those commits belong.
- Expecting a submodule to float to the newest branch tip like a package manager dependency.
Related reading
- What is git remote add ... and git push origin master?
- What is git tag, How to create tags & How to checkout git remote tag(s)
- What is git tag, How to create tags How to checkout git remote tags
- What is HEAD in Git?
- What is origin in Git?
- What is springboot versioning convention?
- What is the correct way to manually commit offset to kafka topic
- What is the difference between git clone and checkout?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.