Git Submodule Pointers and Gitlinks
One project, two histories
A submodule is an independent Git repository used inside a parent repository (superproject). Our garden project depends on a tiny plant library. The parent stores a gitlink (mode 160000) with a child commit ID, not the child files. The tracked .gitmodules file describes the path and source URL. A normal parent clone without initialization has the pointer but not the populated dependency. The parent history does not contain the child history just because it names a commit.
Inspect three different positions
In the provided app fixture, vendor/plants is populated. HEAD in the parent names the committed gitlink, the parent index holds the next proposed gitlink, and the child HEAD names the checked-out commit. These may differ. Compare them before staging. In the initial fixture all three agree on version A. The mode and type shown by ls-tree identify the gitlink. A newer commit in the child source does not automatically update any of these positions.
git ls-tree HEAD -- vendor/plantsgit ls-files --stage -- vendor/plantsgit -C vendor/plants rev-parse HEADgit show HEAD:.gitmodulesWhy a pin is useful
A particular parent snapshot can specify a reproducible dependency revision if the child commit is available from an authorized source. It is not a guarantee that the code is safe or builds. Review the URL, the pinned revision and the child changes. A detached HEAD in a dependency after a normal checkout update is expected: the child is checked out at the recorded commit rather than tracking the latest branch. To develop the child, create or select an appropriate branch in that child repository; publish the child commit before publishing a parent pointer that needs it.
Practice
If the parent points at A but the child HEAD is B, which revision does a fresh initialized clone of the committed parent request? Answer: A. Inspect the parent index as well to decide whether B has already been staged. Never infer the committed pin from the child working directory alone.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Submodule Pointers and Gitlinks — knowledge check
Reason about dependency revisions, ownership and repository boundaries.
What does a gitlink record?
Where is the tracked submodule URL normally described?
Parent HEAD pins A; child HEAD is B. What does a fresh initialized clone of the parent request?
Which command inspects the committed gitlink?
Does the parent gitlink contain the child history?