Interview Q&A / Git & GitHub

AdvancedQuick answer1 min readUpdated 3 Oct 2026

How do you remove a submodule properly?

SHORT ANSWER

Run git submodule deinit -f path, then git rm -f path, and delete the leftover .git/modules/path folder. Commit the change. Just deleting the folder leaves stale configuration behind.

Explain it simply

Removing a submodule is not like deleting a folder, since its registration lives in several places: .gitmodules, the index and .git/modules.

The tidy sequence: git submodule deinit -f libs/ui-kit unregisters it locally, git rm -f libs/ui-kit removes the folder and the .gitmodules entry, and rm -rf .git/modules/libs/ui-kit clears the stored repository. Commit the result. Skipping steps leads to errors such as 'already exists in the index' when adding it again.

Example

bash
git submodule deinit -f libs/ui-kit
git rm -f libs/ui-kit
rm -rf .git/modules/libs/ui-kit
git commit -m "Remove ui-kit submodule"

What to say in the interview

"I run git submodule deinit -f, then git rm -f on the path, remove the leftover directory in .git/modules and commit. Deleting the folder alone leaves stale registration in config and the index."

#git#submodules#cleanup

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.