Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
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.
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:
- Open your terminal and navigate to the root directory of your Git repository:
cd git - Run the following command to unregister the
sha1collisiondetectionsubmodule:git submodule deinit -f -- sha1collisiondetection - Run the following command to remove the directory of the
sha1collisiondetectionsubmodule:rm -rf .git/modules/sha1collisiondetection - Run the following command to remove the working tree of the
sha1collisiondetectionsubmodule: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.