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:

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

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:

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

Now you can delete the submodule folder with the conventional deletion methods of your OS.

[sc name=”src” url=”https://blog.github.com/2016-02-01-working-with-submodules/” ]
[sc name=”src” url=”https://davidwalsh.name/git-remove-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.