An illustration of how to simply incorporate Git submodules

https://www.youtube.com/look at?v=RgIAXF53a8U

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:

  1. Generate a repository with the git init command. This will be the mum or dad module/repository.
  2. Increase documents and accomplish at least a person commit to the mum or dad repository prior to you incorporate Git submodules
  3. Incorporate a new subfolder in the Git repository
  4. Complete a git init in the new subfolder
  5. Incorporate documents and complete at minimum a single commit on the repository in the subfolder
  6. From the root of the dad or mum module, concern a git submodule incorporate command and specify the route to the subfolder
  7. Complete a git status and confirm the mother or father repository consists of a file named .gitmodules
  8. Insert the .gitmodules file to the index and then carry out a commit.

The git submodule incorporate command produce a .gitmodules file.

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:

[email protected]:~$ mkdir surface area
[email protected]:~$ cd area
[email protected] in point:~$ git init
[email protected]:~$ touch destroyer.html
[email protected] in point:~$ git increase .
[email protected]:~$ git commit -m "Incorporate surfae fleet"
[email protected]:~$ mkdir submarines
[email protected]:~$ cd submarines
[email protected]:~$ git init
[email protected]:~$ contact nuclear.html
[email protected]:~$ git include .
[email protected]:~$ git commit -m "Insert submarine to fleet"
[email protected] in point:~$ cd ..
[email protected]:~$ git submodule include ./submarines
[email protected]:~$ git init
[email protected]:~$ git insert .
[email protected]:~$ 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.