One, what is gitmodules
Submodules allow you to use one Git repository as a subdirectory of another Git repository. It allows you to clone another repository into your own project while still keeping the submission independent.
Two, how to use gitmodules
$ git submodule add https://github.com/XXX
By default, the sub-module will place the sub-projects in a directory with the same name as the warehouse, that is, "XXX". If you want to put it elsewhere, you can add a different path at the end of the command. If you run git status at this time, you will notice the new .gitmodules file. The configuration file saves the mapping between the project URL and the local directory that has been pulled. For the configuration of the .gitmodules file, see Chapter 3.
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.Changes to be committed:
(use "git reset HEAD <file>..." to unstage)new file: .gitmodules
new file: XXX
If you want to specify the branch further, you can add the -b parameter. For details, refer to the following:
$ git submodule add
usage: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] deinit [-f|--force] (--all| [--] <path>...)
or: git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--recursive] [--] [<path>...]
or: git submodule [--quiet] absorbgitdirs [--] [<path>...]
Three, .gitmodules configuration
[submodule "abc"]
path = abc
url = http://github.xxx.xxx/xxxx
branch = release
Reference documents:
https://git-scm.com/book/en/v2/Git-Tools-Submodules
https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97