Git submodule
Frequently used commands for Git submodules.
Add a submodule¶
TO add the reference to another git project as a submodule:
git submodule add $url $path
git submodule update --init --recursive
Alternatively, you can use GUI tools like or GitHub desktop. They download and initiate submodules automatically.
Add you will see the file .gitmodules
with information about the submodule(s). For instance,
.gitmodules
[submodule "themes/DoIt"]
path = themes/DoIt
url = https://github.com/HEIGE-PCloud/DoIt.git
Track a specific branch in the submodule¶
With -b $branch
option
git submodule add -b $branch $url $path
Or set-branch -b $branch
if you already have added a submodule
git submodule set-branch -b $branch $path
Update all Git submodules to the latest commit¶
From a stackOverflow post and Git docs
git submodule update --remote --merge
For automated updates by bots, see automatic dependency update.
Remove a submodule¶
From Git docs
# Remove submodule from config
git submodule deinit $path
# Delete submodule tracking data
git rm <submodule path> && git commit
# Complete removal
rm -rf $GIT_DIR/modules/$name/