DEV Community

Zen Oh
Zen Oh

Posted on

How to use git submodule

Git submodule is useful when you need another git repository inside your git project. This repository should not be library managed by dependency manager. Here is useful command I used to manage git submodule.

How to install/add new submodule to current repository

git submodule add <git repository url> <destination folder>
Enter fullscreen mode Exit fullscreen mode

How setup existing submodule in cloned repository

git submodule init
git submodule update
Enter fullscreen mode Exit fullscreen mode

How to update submodule

git submodule update
Enter fullscreen mode Exit fullscreen mode

If you need to update the code inside of the submodule, you can just go to your submodule directory and update the code. After that point your cli to your submodule directory and do a commit & push like normal git repository. Make sure your update won't break another project that already use your submodule.

Top comments (0)