Add Git submodules
This post was not written by any artificial intelligence model.
Sometimes when we want to add another git repository to our project to use it as a dependency, we have a directories structure that needs to have it inside a specific directory. For exmaple, let’s say we have something like this:
.
├── lib
│ └── our_submodule_should_be_here
└── src
└── main.c
So, you just have to go to that directoy, for example:
cd project/lib/
And then run the following command, replacing the repository we want of course.
git submodule add https://github.com/hextreeio/faultier.git
If you wanted that submodule in the root of the project you would simply have to do it in the root.
If you wanted the name of the generated directory to be different than faultier
which is the one that would be generated by the repository name itself, you would have to do it by adding as an option at the end
git submodule add https://github.com/hextreeio/faultier.git other_dir_name
Submodule with submodules
If the submodule that we add has submodules as dependencies, what we have to do is the following:
- Navigate inside the submodule, for the example:
cd faultier/
- Register the submodules
git submodule init
- Update the submodules
git submodule update
We would have something like the following:
❯ git submodule init
Submodule 'nanopb' (https://github.com/nanopb/nanopb.git) registered for path 'nanopb'.
faultier on main via C v16.0.0-clang via △ v3.30.3
❯ git submodule update
Cloning into '/Users/deimos/dev/embedded/electronic_cats/faultycat/firmware/c/faultier/nanopb'...
Submodule path 'nanopb': checked out 'e34dfae6f1aeb87cbe1c05a8fb96f5b9cb1034f6'