Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
In Git, submodules are repositories within repositories. They allow you to include other repositories as dependencies in your project. When you clone a Git repository that contains submodules, the submodules are not automatically cloned. This can cause issues when trying to build or run the project. In this lab, you will learn how to clone missing submodules and checkout commits.
Clone Missing Submodules
You are working on a project that contains submodules. When you clone the project, the submodules are not automatically cloned. This causes issues when trying to build or run the project. You need to clone the missing submodules and checkout the correct commits.
For this lab, we will use the Git repository named https://github.com/git/git. This repository contains submodules that are not automatically cloned when you clone the repository.
To clone the missing submodules and checkout the correct commits, follow these steps:
- Change into the repository directory:
cd git - Initialize the submodules:
git submodule update --init --recursive - Checkout to the correct commit of the submodule, i.e. the
masterbranch:
Here's the final result:git submodule foreach git checkout master
Submodule 'sha1collisiondetection' (https://github.com/cr-marcstevens/sha1collisiondetection.git) registered for path 'sha1collisiondetection'
Cloning into '/home/labex/project/git/sha1collisiondetection'...
Submodule path 'sha1collisiondetection': checked out '855827c583bc30645ba427885caa40c5b81764d2'
Summary
Cloning missing submodules and checking out commits is an important step when working with Git repositories that contain submodules. By following the steps outlined in this lab, you can ensure that your project builds and runs correctly.