September 02, 2013
Removing a Git submodule is nowhere near as easy as adding one. In my projects I typically use a submodule for managing dependencies that are themselves a Git repository. When that dependency goes away it is necessary to remove the submodule. Here’s how I go about that task.
First delete the relevant section from the
.gitmodules file at the root of the parent project. This section will have this format:
Next stage the
Now delete the relevant section from the
config file located in the
.git directory at the root of the project. It will look something like this:
Now it’s time to use
git rm to tell Git to stop tracking the submodule.
Be careful not to include a trailing slash on the
git rm command as it will cause errors.
Now that no longer is tracking the submodule it can be deleted from the file system.
Commit the changes to the repository.
Finally you can delete the actual submodule.
That’s it. The submodule has been completely removed from Git and removed from the file system.