subproject commit
version control
software development
git
project management

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.

bash
git submodule add https://github.com/example/shared-lib.git vendor/shared-lib
git commit -m "Add shared library as submodule"

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:

bash
1cd vendor/shared-lib
2git checkout main
3git pull
4git commit --allow-empty -m "Example submodule change"
5cd ../..
6git status

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:

bash
git add vendor/shared-lib
git commit -m "Update shared-lib submodule pointer"

The workflow always has two layers:

  1. commit in the submodule if the child code changed
  2. 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:

bash
git clone https://github.com/example/app.git
cd app
git submodule update --init --recursive

After pulling parent changes, the same command moves submodules to the commits the parent now expects:

bash
git pull
git submodule update --init --recursive

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:

bash
cd vendor/shared-lib
git checkout main

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 pull in 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.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Interview Questions practice on Codemia

Over 11,000 interview practice questions for 300+ companies, searchable by company and role.

Browse interview questions