Git Submodules

Fri 06 August 2021

Add a submodule

You can add either a HTTPS or SSH URL (SSH is most convenient) E.g. for github an HTTS URL looks like: https://github.com/... and SSH URL looks like: git@github.com:.... The URL can be picked from the github UI (Code button dropdown box).

git submodule add <remote_url> <destination_folder>

After adding a submodule or cloning a repository with submodules, you will need to actually pull the submodules:

git submodule update --init --recursive

Change the commit point of a submdule

git cd <submodule path>
git branch -v
git checkout <branch>
git pul
cd <root>
git add <submodule_path>
git commit -m "update submodule commit point"
git push

List all submodule paths

git config --file .gitmodules --get-regexp path | awk '{ print $2 }'

Remove a submodule

git submodule deinit <path_to_submodule>
git rm <path_to_submodule>
rm -rf <path_to_submodule>
rm -rf ./git/modules/submodules/<submodule-dir>
git commit -m "Removed submodule"
git push

Category: Git