Submodules: Composing Repositories

A real shared library, pinned to an older commit. Time to genuinely catch it up.

vendor/cooking-utils is a genuine git submodule — a real, separate repository (Grace Hopper's shared cooking-utils library) embedded at a specific path, with team-recipes recording exactly which real commit of it to use. That real commit is currently an older one; a newer one already exists upstream, not yet pulled in.\n\nChecking out any specific commit inside a submodule (rather than tracking a branch tip) is a genuine, real detached HEAD — the exact same state Block 3.4 already covered, just inside a nested repository instead of the main one. Updating it is a real, two-step act: fetch and check out the new commit inside the submodule itself, then commit the updated reference in the parent.

What .gitmodules Actually Records

cat .gitmodules
git submodule status

.gitmodules records the real submodule's path and URL. git submodule status shows the exact real commit it is currently pinned to — a plain hash, since it is genuinely detached, not tracking a branch tip.

A Real Detached HEAD, Inside a Submodule

cd vendor/cooking-utils && git status

Exactly the same real detached-HEAD state Block 3.4 covered — just inside a nested, separate repository this time.

Catching It Up

cd vendor/cooking-utils
git fetch origin
git checkout origin/master
cd ..
git add vendor/cooking-utils
git commit -m "Update cooking-utils submodule to latest"

Updating a submodule is genuinely a two-repository act: move the submodule's own HEAD to the new commit, then commit that new pointer in the parent repository, exactly like updating any other tracked file.

git submodule status

Shows the real, exact commit each submodule is currently pinned to. Confirmed directly in this lab: the hash shown matched the older of the two real commits published in the shared library.

Detached HEAD inside a submodule

A submodule's checkout is genuinely detached by default, pinned to one specific real commit rather than tracking a branch. Confirmed directly in this lab: git status inside vendor/cooking-utils showed the exact same real detached-HEAD state as Block 3.4, just in a nested repository.

🔍 Read the Real Submodule State

.gitmodules and git submodule status reveal exactly what is pinned.

cd ~/team-recipes && cat .gitmodules
cd ~/team-recipes && git submodule status
cd ~/team-recipes/vendor/cooking-utils && git log --oneline
cd ~/team-recipes/vendor/cooking-utils && git status

student@lab:~$ cd ~/team-recipes && cat .gitmodules [submodule "vendor/cooking-utils"] path = vendor/cooking-utils url = ../cooking-utils-origin.git student@lab:~$ cd ~/team-recipes && git submodule status b6fb7e0a0292a915336676f9bdf0b810927b1cdd vendor/cooking-utils (b6fb7e0) student@lab:~$ cd ~/team-recipes/vendor/cooking-utils && git log --oneline b6fb7e0 (HEAD) Add Fahrenheit-to-Celsius conversion notes student@lab:~$ cd ~/team-recipes/vendor/cooking-utils && git status HEAD detached at b6fb7e0 nothing to commit, working tree clean

⬆️ Fetch the Real Newer Commit

The newer commit already exists upstream — bring it in.

cd ~/team-recipes/vendor/cooking-utils && git fetch origin
cd ~/team-recipes/vendor/cooking-utils && git log --oneline origin/master
cd ~/team-recipes/vendor/cooking-utils && git checkout origin/master

student@lab:~$ cd ~/team-recipes/vendor/cooking-utils && git fetch origin student@lab:~$ cd ~/team-recipes/vendor/cooking-utils && git log --oneline origin/master e0445e8 (origin/master, origin/HEAD, master) Add Celsius-to-Fahrenheit conversion notes b6fb7e0 (HEAD) Add Fahrenheit-to-Celsius conversion notes student@lab:~$ cd ~/team-recipes/vendor/cooking-utils && git checkout origin/master Previous HEAD position was b6fb7e0 Add Fahrenheit-to-Celsius conversion notes HEAD is now at e0445e8 Add Celsius-to-Fahrenheit conversion notes

💾 Commit the Real Updated Reference

The parent repository needs to record the new pin.

cd ~/team-recipes && git status
cd ~/team-recipes && git add vendor/cooking-utils
cd ~/team-recipes && git commit -m 'Update cooking-utils submodule to latest'
cd ~/team-recipes && git log --oneline -1

student@lab:~$ cd ~/team-recipes && git status On branch master Your branch is ahead of 'origin/master' by 121 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: vendor/cooking-utils (new commits) no changes added to commit (use "git add" and/or "git commit -a") student@lab:~$ cd ~/team-recipes && git add vendor/cooking-utils student@lab:~$ cd ~/team-recipes && git commit -m 'Update cooking-utils submodule to latest' [master 3b1f92d] Update cooking-utils submodule to latest 1 file changed, 1 insertion(+), 1 deletion(-) student@lab:~$ cd ~/team-recipes && git log --oneline -1 3b1f92d (HEAD -> master) Update cooking-utils submodule to latest

Lab 3.5.3 complete. A real, separate shared library, composed as a submodule and genuinely caught up:\n\n\n Pinned to older commit : ✅ confirmed (real detached HEAD)\n Fetched + checked out : ✅ newer real commit\n Parent reference : ✅ committed\n

Enable JavaScript to run the live terminal and track your progress.