跳至主要內容

Things about git submodule

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:

https://stackoverflow.com/questions/10914022/how-do-i-check-out-a-specific-version-of-a-submodule-using-git-submodule

https://myapollo.com.tw/blog/git-tutorial-submodule/

分類:Git

搶先發佈留言

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

由 Compete Themes 設計的 Author 佈景主題