Git Submodules
Use submodules when you want to treat two projects as separate yet still be able to use one from within the other.
- (Notes from https://git-scm.com/book/en/v2/Git-Tools-Submodules)
- 🔑 Submodules allow you to keep a Git repo as a subdirectory of another Git repo
- Can clone another repo into your project and keep your commits separate
Example 1: Add an existing Git repo as a submodule of the repo you're working on
git submodule add [repo-url]
- By default, submodules add the subproject into a directory named the same as the repo -- add a different path for
[repo-url]to make it go elsewhere - Viewing
.gitmoduleswill show something like: (below is for QR)
[submodule "src/qr_mapping/dependencies/common_robotics_utilities"]
path = src/qr_mapping/dependencies/common_robotics_utilities
url = https://github.com/siddancha/common_robotics_utilities.git
[submodule "src/qr_mapping/dependencies/voxelized_geometry_tools"]
path = src/qr_mapping/dependencies/voxelized_geometry_tools
url = https://github.com/siddancha/voxelized_geometry_tools.git
[submodule "src/qr_fault/planners/motion-planners"]
path = src/qr_fault/planners/motion-planners
url = [email protected]:caelan/motion-planners.git
- To also initialize, fetch and checkout any nested submodules, you can use the foolproof
git submodule update --init --recursive.