An intro and cheatsheet for using git submodules.
$ git submodule add https://github.com/USERNAME/REPONAME PATHe.g.
$ git submodule add https://github.com/hexojs/hexo-theme-landscape themes/landscapeThe submodule will already be staged:
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitmodules
new file: themes/landscape
So just commit.
Here are sample contents:
.gitmodulesconfig (in.iniformat).[submodule "themes/landscape"] path = themes/landscape url = https://github.com/hexojs/hexo-theme-landscape
themes/landscape- just a reference to a commit inside the submodule repo (in.diffformat).diff --git a/themes/landscape b/themes/landscape new file mode 160000 index 0000000..f20626c --- /dev/null +++ b/themes/landscape @@ -0,0 +1 @@ +Subproject commit f20626cb882890bfc596b2fede01d8e80ea8f02e
To include submodule, clone the main repo with the --recursive flag.
$ git clone --recursive https://github.com/USERNAME/REPO_NAMEIf you forgot to use the flag when you cloned, then just do this:
$ git submodule init
$ git submodule updateWhen you want to update a submodule to a newer version:
git submodule updateView help:
$ git submodule --helpSee also git submodules in the git docs.