Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

Why is a submodule in detached HEAD state, and is that a problem?

SHORT ANSWER

The parent pins an exact commit, so Git checks the submodule out at that commit, not on a branch. It is normal. To edit the submodule, check out a branch inside it first, or commits can get lost.

Explain it simply

The parent said 'edition 3, page 40', not 'whatever is newest', so Git opens the child at that exact commit with no branch attached.

Reading is fine. The trap is editing: commit in a detached submodule, then run git submodule update, and Git moves back to the pinned commit, leaving your work unreferenced. Do git switch main inside the submodule before changes, commit and push there, then record the new pointer in the parent. Set branch in .gitmodules to track a branch with --remote.

Example

bash
cd libs/ui-kit
git switch main          # leave detached HEAD
# edit, commit, push
cd ..
git add libs/ui-kit && git commit -m "Update ui-kit pointer"

What to say in the interview

"Detached HEAD is expected because the parent pins a commit. Before changing a submodule I switch to a branch there, commit and push, then update the pointer in the parent so nothing is lost."

#git#submodules#head

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.