git submodule's Examples

If you want to make sub folder in your git repository like git/firstrepository/subrepository. you simply copy the url of repository and paste with "git submodule url".

git submodule add repo_url

if you want to delete sub folder of your repository file.you just a command git submodule remove command.

git submodule remove repo_file

Adds a new submodule to your repo

git submodule add https://github.com/user/lib.git lib/

Initializes submodules listed in .gitmodules

git submodule init

Clones and checks out the correct commit for each submodule

git submodule update

Clones and checks out the correct commit for each submodule

git submodule update

Clones and checks out the correct commit for each submodule

git submodule update

Shorthand to init and update in one go

git submodule update --init

Initializes and updates submodules and any nested submodules

git submodule update --init --recursive

Syncs submodule URLs with .gitmodules

git submodule sync

Syncs submodule URLs with .gitmodules

git submodule sync

Syncs submodule URLs with .gitmodules

git submodule sync

Runs a command in each submodule

git submodule foreach 'git pull origin main'

Displays current commit and status of each submodule

git submodule status

Unregisters a submodule

git submodule deinit lib/

Removes submodule from index

git rm --cached lib/

Deletes submodule folder (manual step)

rm -rf lib/

Deletes .gitmodules if no submodules remain

rm .gitmodules

Shows summary of changes in submodules

git submodule summary

Manage submodules.

git submodule add https://repo.git lib/

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us