There are many ways a developer can include Git submodules to an present repository. They can clone from GitLab, they can do a Git submodule increase from GitHub or they can manually produce all their repositories and submodules.
This tutorial will target on the latter approach, which will include a Git submodule insert case in point that doesn’t have to have any integration with GitHub and does not have to have any pre-current repositories. It is a basic, bare bones strategy to learn how the Git submodule add command performs, and it is the most effective way to find out how submodules in Git work.
How to include Git submodules
A developer can adhere to these 8 techniques to include Git submodules:
- Generate a repository with the git init command. This will be the mum or dad module/repository.
- Increase documents and accomplish at least a person commit to the mum or dad repository prior to you incorporate Git submodules
- Incorporate a new subfolder in the Git repository
- Complete a git init in the new subfolder
- Incorporate documents and complete at minimum a single commit on the repository in the subfolder
- From the root of the dad or mum module, concern a git submodule incorporate command and specify the route to the subfolder
- Complete a git status and confirm the mother or father repository consists of a file named .gitmodules
- Insert the .gitmodules file to the index and then carry out a commit.
If a developer completes these steps and does not get an error information, they will have productively carried out a git submodule insert.
Git submodule add instructions
The true commands used in the instance are:
submodule@instance:~$ mkdir surface area submodule@instance:~$ cd area submodule@case in point:~$ git init submodule@example:~$ touch destroyer.html submodule@case in point:~$ git increase . submodule@example:~$ git commit -m "Incorporate surfae fleet" submodule@instance:~$ mkdir submarines submodule@illustration:~$ cd submarines submodule@illustration:~$ git init submodule@illustration:~$ contact nuclear.html submodule@example:~$ git include . submodule@example:~$ git commit -m "Insert submarine to fleet" submodule@case in point:~$ cd .. submodule@example:~$ git submodule include ./submarines submodule@instance:~$ git init submodule@illustration:~$ git insert . submodule@illustration:~$ git commit -m "Increase the submodule submarines"
How to increase submodules in GitLab
If a developer employs GitLab as their repository of preference, this video demonstrates how to do a Git submodule add with GitLab.
Additional git submodule insert illustrations
I executed this Git submodule increase example locally by initializing all the needed repositories. To see how to insert a submodule via a clone, you may well want to check out this GitHub submodule case in point.