DEV Community

Cover image for Git Tools - Submodules
Hamed0406
Hamed0406

Posted on

Git Tools - Submodules

What is Submodules and why developer need it ?

Git Tools - Submodules is tools to let developer have a child repository under a parent repository .

in other words as git official document said :
"Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate." [1]

configuration file for Git-Submodules is ".gitmodules" .
The new submodule can be added by this command :

git submodule add the absolute or relative URL of the project

for example :

git submodule add https://gitlab.com/Hamed0406/springboot-dashboed
after running the command this lines will be added to

[submodule "springboot-dashboed"]
    path = springboot-dashboed
    url = https://gitlab.com/Hamed0406/springboot-dashboed

Enter fullscreen mode Exit fullscreen mode

to .gitmodules file.

Note : if you have private repo as submodules and share your project with others, you have to be sure they have access to the private repo.

References

  1. git-scm.com , [https://git-scm.com/book/en/v2/Git-Tools-Submodules]

Top comments (0)