Published Mar 15, 2025
[
 
]
A Git submodule is a way to include one Git repository inside another. This is useful when you want to manage dependencies or separate concerns in a modular fashion.
git submodule add <repository-url> <path>
This adds a submodule and records its exact commit in your project.
By default, git clone
does not pull submodules. To clone a repo with submodules, use:
git clone --recursive <repository-url>
If you forgot --recursive
, initialize submodules manually:
git submodule update --init --recursive
To update the submodule to the latest commit from its repository:
cd <submodule-path>
git pull origin main # Update the submodule to the latest commit
cd ..
git add <submodule-path>
git commit -m "Updated submodule"
git submodule deinit -f <path>
git rm -f <path>
rm -rf .git/modules/<path>
This removes all traces of the submodule from your repo.
Let me know if you need more details! 🚀