How to Remove a GIT Submodule

To remove a Git submodule, you can follow these steps:

  1. Open a terminal or command prompt and navigate to the root directory of your Git repository.

  2. Run the following command to see a list of submodules in your repository:

    git submodule status
    

    This will display the submodule path and commit hash.

  3. Identify the submodule you want to remove from the list.

  4. Run the following command to remove the submodule:

    git submodule deinit <submodule-path>
    

    Replace <submodule-path> with the path to the submodule you want to remove.

  5. Run the following command to remove the submodule from the repository:

    git rm <submodule-path>
    

    Again, replace <submodule-path> with the path to the submodule.

  6. Commit the changes:

    git commit -m "Remove submodule: <submodule-path>"
    

    Replace <submodule-path> with the path to the submodule.

  7. Lastly, delete the submodule directory from your local filesystem. The submodule’s files will be removed from the Git repository, but the actual files on your computer won’t be automatically deleted by Git.

    rm -rf <submodule-path>
    

    Replace <submodule-path> with the path to the submodule.

That’s it! The submodule should now be removed from your Git repository.