0
0
Gitdevops~20 mins

Why submodules manage nested repos in Git - See It in Action

Choose your learning style9 modes available
Why Submodules Manage Nested Repos
📖 Scenario: Imagine you have a main project that uses another project inside it. This other project is a separate repository. You want to keep them connected but separate, like having a toolbox inside your main toolbox.
🎯 Goal: You will learn how to add a nested repository inside a main repository using Git submodules. This helps manage projects inside projects clearly and safely.
📋 What You'll Learn
Create a main Git repository
Add a nested Git repository as a submodule
Check the submodule status
Display the list of submodules
💡 Why This Matters
🌍 Real World
Many projects depend on other projects. Using submodules helps keep these dependencies organized and separate, like having smaller toolkits inside a big toolbox.
💼 Career
Understanding Git submodules is important for developers and DevOps engineers to manage complex projects with multiple repositories efficiently.
Progress0 / 4 steps
1
Create the main Git repository
Create a new directory called main_project and initialize it as a Git repository using git init.
Git
Need a hint?

Use mkdir to make a folder, cd to enter it, and git init to start a Git repo.

2
Add a nested Git repository as a submodule
Inside main_project, add a submodule named nested_repo from the URL https://github.com/example/nested_repo.git using git submodule add.
Git
Need a hint?

Use git submodule add <URL> <folder_name> to add the nested repo.

3
Check the submodule status
Use git submodule status inside main_project to see the current state of the submodule.
Git
Need a hint?

Run git submodule status to see the submodule commit and path.

4
Display the list of submodules
Use git config --file .gitmodules --name-only --get-regexp path to list the paths of all submodules in main_project.
Git
Need a hint?

This command reads the .gitmodules file to show submodule paths.