Skip to content

Working with Submodules

For the introduction, I like to quote a part of Github’s submodule guide "Working with submodules":

Eventually, any interesting software project will come to depend on another project, library, or framework. Git provides submodules to help with this. Submodules allow you to include or embed one or more repositories as a sub-folder inside another repository.

Adding a submodule

And to use it, imagine we have a repository called desktop. This repo needs to call functions from a library in another repo, called api.

To add the api repo as a submodule to desktop, run this command:

git submodule add [repository link] [local directory name]

Now a empty directory was created. To get all the files of that submodule, run:

git submodule update --init --recursive

Now git will clone that submodule repo, so that you can work with its code.

Remove a submodule

Edit your .gitmodules file and remove the part relevant to your submodule. Example:

[submodule "vendor"]
	path = vendor
	url = git://

Then run the following command to remove the tracking of the submodule (Note: Make sure that the path doesn’t include a trailing slash):

git rm --cached path/to/submodule



Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.