How to Remove a Git Submodule

  1. Steps to removing submodule
    1. Removing entry and submodule directory
    2. Staging changes
    3. Deleting from .git/config
    4. Unstaging and removing file only from the index
    5. Deleting untracked files
    6. Committing changes
    7. Cleaning submodule in local cloned copy
  2. The git rm Command
  3. The git commit Command

Git submodule represents a record in a host git repository pointing to a particular commit in another external repository. The file of the .gitmodule includes meta data on how to map amid the URL of the submodule project and local directory. It is necessary to remove the submodule in case it is not required anymore.

Steps to removing submodule

Here is the step-by-step guide to delete the unnecessary submodule:

Removing entry and submodule directory

To remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule, you should invoke the following:

[submodule "vendor"]
	path = vendor
	url = git://

Staging changes

Next step is staging the changes via:

git add .gitmodules

It will look like this:

[submodule "vendor"]
	url = git://

Deleting from .git/config

In the framework of the next step, you should delete the relevant section from:


Unstaging and removing file only from the index

Now you need to delete the appropriate section from:

git rm --cached path/to/submodule

Deleting untracked files

Invoke the following to delete the untracked files:

rm -rf .git/modules/submodule_name

Committing changes

Go on with committing your changes using git commit:

git commit -m "Removed submodule <name>"

Cleaning submodule in local cloned copy

This step should be run to clean the submodule completely in local cloned copy:

rm -rf path/to/submodule

Following the above-given steps, you will manage to remove an unwanted submodule easily.

The git rm Command

The git rm command helps to remove particular files or a group of files from a repository. It is mainly aimed at removing tracked files from the index. It can also remove files from the working directory and staging index. But, note, that you can’t remove it merely from the working directory. Besides, git rm can’t remove branches.

The git commit Command

The git commit command is mainly used for saving the overall current changes of your project. You can create commits for capturing the ongoing state of your project. The committed captures are safe, as Git asks before starting to change them. The git add command is invoked for promoting changes to the project, before running git commit.

Do you find this helpful?

Related articles