How do I remove a submodule?

64    Asked by lois_6906 in Devops , Asked on Aug 26, 2025

How do you properly remove a Git submodule from your repository? What steps are required to clean up its configuration and files completely?

Answered by Dylan PEREZ

When working with Git repositories, you might add a submodule for dependency management, but later realize you don’t need it anymore. This raises the question: “How do I remove a submodule cleanly?” Simply deleting the folder isn’t enough—you also need to remove its configuration and references.

Step 1: Deinitialize the Submodule

 Run the following command to remove the submodule from Git’s configuration:

   git submodule deinit -f path/to/submodule

Step 2: Remove from Index

 Next, remove the submodule entry from the Git index (staging area):

   git rm -f path/to/submodule

 This deletes the submodule directory and stages the removal for commit.

Step 3: Delete Submodule Files

 Git stores submodule data in the .git/modules directory. To remove it completely:

   rm -rf .git/modules/path/to/submodule

Step 4: Commit the Changes

 Finally, commit the removal so the repository no longer tracks the submodule:

   git commit -m "Removed submodule path/to/submodule"

 Key Takeaway:

 To fully remove a submodule, you must (1) deinitialize it, (2) remove it from the index, (3) delete its module data, and (4) commit the changes. Skipping these steps may leave behind hidden configuration files that can cause issues later.



Your Answer

Interviews

Parent Categories