Git Submodules: Advanced Usage and Strategies on Ubuntu
Git Bash is an open-source tool that is specially designed for developers to manage their projects on sources like GitHub and GitLab. On hosts like Github, every user is assigned a specific module to work on and then later on, it will be merged. However, if the developers want to make another repository inside the existing repository, it is known as a Git submodule.
The article will talk about:
What are Git Submodules in Git?
As mentioned earlier, Git submodules are the repository inside an existing repository that is utilized for keeping the record of external commits/dependencies in the project. Moreover, it doesn’t track the git branches nor update automatically when the hosted repository is updated.
How to Add Git Submodules in Git on Ubuntu?
For adding the Git submodules in Git on Ubuntu, walk through the below-provided steps.
Step 1: Check Git
Open the terminal and let’s check the version of Git using the following command:
Git version 2.34.1 is available for use.
Step 2: Create a Directory
Create the directory using the “mkdir” command:
In our case, we have created the “sub-modules” directory.
Step 3: Move to the Created Directory
After that, move to the created directory with the help of the “cd” command:
Step 4: Initialize Repository
Initialize the created Git repository by executing the “git init” command:
The project repository has been initialized.
Step 5: Copy the Repository URL
Afterward, open the Git repository on GitHub and copy the HTTPS URL by opening the “Code” dropdown as highlighted:
Step 6: Add Submodule
After copying the repository, add the git submodules using the command and specify the copied URL of the particular repository:
The submodule has been cloned.
Step 7: Check Status
Now, check the status of the cloned submodule using the “git status” command:
The above output shows that there are no commits yet.
Step 8: Commit Changes
Let’s commit some changes in the project using the “git commit” command:
The changes have been committed.
Git submodules are the repository inside an existing repository that is utilized for keeping the record of external commits/dependencies in the project. To add a sub-module on Ubuntu, create and initialize the directory. After that, copy the HTTPS URL of the GitHub repository and use the “git submodule add <HTTPS Link>” command to add the submodule. This write-up has provided a detailed guide about Git submodules.