Linux command
git-submodule 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Add submodule
git submodule add [url] [path]
Initialize submodules
git submodule init
Update submodules
git submodule update
Clone with submodules
git submodule update --init --recursive
Show submodule status
git submodule status
Pull submodule changes
git submodule update --remote
Remove submodule
git submodule deinit [path] && git rm [path]
Run a command in each submodule
git submodule foreach '[command]'
Sync submodule URLs
git submodule sync --recursive
说明
git submodule manages submodules, which are external Git repositories embedded within a parent repository at specific paths. Each submodule tracks a particular commit of the external repository. Submodules allow projects to include and track dependencies or shared components while keeping their histories separate. Use `update --init --recursive` after cloning to populate all submodule contents.
参数
- --init
- Initialize uninitialized submodules before updating.
- --recursive
- Recurse into nested submodules.
- --remote
- Use the submodule's remote tracking branch instead of the superproject's recorded SHA-1.
- -f, --force
- Force checkout even if the submodule already matches.
- -b _branch_, --branch _branch_
- Branch of repository to track (add, set-branch).
- -j _n_, --jobs _n_
- Clone new submodules in parallel with n jobs.
- -q, --quiet
- Only print error messages.
- --depth _depth_
- Create a shallow clone with truncated history.
- -N, --no-fetch
- Do not fetch new objects from the remote (update).
FAQ
What is the git-submodule command used for?
git submodule manages submodules, which are external Git repositories embedded within a parent repository at specific paths. Each submodule tracks a particular commit of the external repository. Submodules allow projects to include and track dependencies or shared components while keeping their histories separate. Use `update --init --recursive` after cloning to populate all submodule contents.
How do I run a basic git-submodule example?
Run `git submodule add [url] [path]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --init do in git-submodule?
Initialize uninitialized submodules before updating.