Delete a Submodule

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In Git, a submodule is a repository that is included in another repository as a subdirectory. Submodules allow you to keep a separate repository for a specific project within a larger project. However, there may be situations where you need to delete a submodule from your repository. In this lab, you will learn how to delete a submodule from a Git repository.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/GitHubIntegrationToolsGroup(["`GitHub Integration Tools`"]) git/GitHubIntegrationToolsGroup -.-> git/submodule("`Manage Submodules`") subgraph Lab Skills git/submodule -.-> lab-12726{{"`Delete a Submodule`"}} end

Delete a Submodule

You have a Git repository that includes a submodule named sha1collisiondetection. You want to delete this submodule from your repository.

For this lab, we will use the Git repository named https://github.com/git/git. This repository includes a submodule named sha1collisiondetection.

To delete the sha1collisiondetection submodule from the repository, follow these steps:

  1. Open your terminal and navigate to the root directory of your Git repository:
    cd git
  2. Run the following command to unregister the sha1collisiondetection submodule:
    git submodule deinit -f -- sha1collisiondetection
  3. Run the following command to remove the directory of the sha1collisiondetection submodule:
    rm -rf .git/modules/sha1collisiondetection
  4. Run the following command to remove the working tree of the sha1collisiondetection submodule:
    git rm -f sha1collisiondetection

After these steps, the sha1collisiondetection submodule will be removed from your Git repository. If you run the git submodule status command, you won't get any information about the submodule.

Summary

In this lab, you learned how to delete a submodule from a Git repository. You used the git submodule deinit, rm, and git rm commands to unregister the submodule, remove its directory, and remove its working tree, respectively. By completing this challenge, you should now be able to delete submodules from your Git repositories with ease.

Other Git Tutorials you may like