DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Git - Adding Submodule

Adding a Submodule to a Git Repository

Adding a submodule to your git repository is actually quite simple. For example, if you are in the working directory of the repository, to add a new submodule:

$ git submodule add <git url>
Enter fullscreen mode Exit fullscreen mode
  • git submodule add – This simply tells Git that we are adding a submodule. This syntax will always remain the same.
  • <git url> – This is the external repository that is to be added as a submodule.

If you want to more control over add feature:

$ git submodule add -b <branch> <git url> <folder/subfolder>
Enter fullscreen mode Exit fullscreen mode
  • <branch> – This fetching different branch from your default branch, e.g master
  • <folder/subfolder> – This add your submodule to another subfolder

to activate the submodule:

$   git submodule init
Enter fullscreen mode Exit fullscreen mode

Top comments (0)