A Git submodule is a repository embedded inside another repository. It allows you to keep a separate project within your main project, tracking its own history.
Click to reveal answer
beginner
What is the first step to remove a Git submodule?
The first step is to remove the submodule entry from the .gitmodules file and stage the change with git add .gitmodules.
Click to reveal answer
intermediate
Why do you need to remove the submodule directory from the Git index?
Because the submodule is tracked as a separate repository, you must remove it from the Git index with git rm --cached <path> to stop tracking it.
Click to reveal answer
beginner
What command removes the submodule directory from your working directory after untracking it?
You manually delete the submodule directory using a command like rm -rf <path> to remove the files from your working directory.
Click to reveal answer
beginner
What is the final step to complete submodule removal?
Commit the changes to .gitmodules and the removal of the submodule from the index and working directory to finalize the removal.
Click to reveal answer
Which file must you edit to remove a Git submodule?
AREADME.md
B.gitmodules
C.gitignore
D.git/config
✗ Incorrect
The .gitmodules file contains the configuration for submodules and must be updated to remove a submodule.
What does the command 'git rm --cached <submodule_path>' do?
ARemoves the submodule from the Git index but keeps files locally
BDeletes the submodule files from disk
CAdds the submodule to the index
DUpdates the submodule to the latest commit
✗ Incorrect
The --cached option removes the submodule from Git tracking but leaves the files in your working directory.
After removing a submodule from .gitmodules and the index, what should you do next?
ACreate a new submodule
BRun git submodule update
CDelete the submodule directory manually
DPush to remote without committing
✗ Incorrect
You must manually delete the submodule directory to remove its files from your working directory.
Why is it important to commit changes after removing a submodule?
ATo save the removal changes in the repository history
BTo create a new submodule
CTo update the remote submodule
DTo reset the repository
✗ Incorrect
Committing saves the removal steps so others see the submodule is no longer part of the project.
Which command sequence correctly removes a submodule named 'lib'?
4. You ran rm -rf mysub before git submodule deinit mysub. What problem might occur?
medium
A. Git still tracks the submodule and shows errors on next fetch
B. The submodule folder is restored automatically
C. Git removes the submodule automatically without errors
D. No problem, this is the correct order
Solution
Step 1: Understand order importance
Deleting the folder before unregistering leaves Git still tracking the submodule path.
Step 2: Resulting error state
Git will show errors or warnings because the submodule is missing but still registered.
Final Answer:
Git still tracks the submodule and shows errors on next fetch -> Option A
Quick Check:
Delete folder before deinit causes tracking errors [OK]
Hint: Always deinit before deleting submodule folder [OK]
Common Mistakes:
Deleting folder first then deinit
Ignoring Git errors after removal
Assuming folder deletion unregisters submodule
5. You want to completely remove a submodule named libs/toolkit from your project. Which sequence of commands correctly removes it and cleans all related data?