gitpractice.dev

home — Ch.10 · Work with a submodule

Exercise 5 of 6

Before you start

Submodules

A submodule puts another repository in a folder of yours. Your project does not copy its files: it records which commit of that repository to use, and lists its address in a file called .gitmodules.

Cloning leaves the folder empty

A plain clone does not download submodules. Ask for them while cloning, or afterwards.

git clone <url>
clone, submodule folders stay empty
git clone --recurse-submodules <url>
clone with the submodules
git submodule update --init
download them after cloning

Moving to a newer commit

A submodule stays on the recorded commit even when its repository moves on. To upgrade, move it, then commit the new pointer in your project. git status shows (new commits) until you do.

After a git pull that moved the pointer, run git submodule update to check out what the team recorded.

git submodule update --remote
move to the newest commit of its repository
git add <folder>
stage the new pointer
git commit -m "What you upgraded"
record it
git push
share it
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path