While developing a new project, it’s possible that you may need to leverage some modules or code from other project.
Then it comes out git submodule. By using git submodule, you can also control the version of the module or keep the version up to date.
How to do it?
You can easily use following command to do so…
# git submodule add <repository> <submodule path>
For example:
# git submodule add https://github.com/kohya-ss/sd-scripts kohya_trainer
Once the submodule is added, you can see there is a .gitmodules
file in your repo like below.
[submodule "kohya_trainer"]
path = kohya_trainer
url = https://github.com/kohya-ss/sd-scripts
How to checkout specific version?
Submodule stays in a detached HEAD, so you can just cd to the submodule, then checkout the commit or branch you want.
# cd kohya_trainer
# git checkout [commit]
# git checkout [branch]
How to clone repository with submodules?
The laziest way is
# git clone --recurse-submodules [repository]
If you want to do step by step, then…
# git clone [repository]
# cd [repository]
# git submodule init
# git submodule update
How to delete submodule?
# git rm [submodule path]
Reference:
搶先發佈留言