Skip to content
Justice Tech School

Submodules

A submodule pins another repository at a commit inside yours. Use it for shared libraries, and clone with --recurse-submodules.

Example
git init -q --bare -b main ../lib.git
git clone -q ../lib.git ../libwork && (cd ../libwork && git config user.name A && git config user.email a@x.com && echo lib > l.txt && git add l.txt && git commit -qm lib && git push -q)
echo one > a.txt && git add a.txt && git commit -qm 'first'
git -c protocol.file.allow=always submodule add -q ../lib.git vendor/lib
cat .gitmodules | head -2

Result

[submodule "vendor/lib"]
	path = vendor/lib

Exercise

Add a submodule.

git submodule  url path

Quiz Test

Where are submodules listed?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.