Git submodule
Git submodule
March 24, 2024
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 --recursiveAlternatively, 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.gitTrack a specific branch in the submodule
With -b $branch option
git submodule add -b $branch $url $pathOr set-branch -b $branch if you already have added a submodule
git submodule set-branch -b $branch $pathUpdate all Git submodules to the latest commit
From a stackOverflow post and Git docs
git submodule update --remote --mergeFor 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/Last updated on