Dipu Dey 17th Oct 2022

Git submodule is a way to reuse code across multiple projects. It is usually code embedded with the main repository. The submodule repository code doesn’t add the main repository code.

Sometimes you don’t work with the latest submodule code, so if you are using submodules, your submodule’s code will not update automatically if you don’t want it to.

Add Submodule to Repository


git submodule add repository_link your_directory

Example:


git submodule add https://github.com/codeboxrcodehub/pathao-courier.git couriercompany

After running this command a new file is added to your root directory called .gitmodules and pulls your repository code. This file is a list of all submodule lists and repository lists.

Update Submodule in Local Repository

Submodules do not update automatically. so if you want to update the code then run.


git submodule update --recursive --remote

If it’s the first time you check out a repository you need to use


git submodule update --init

If you change or add any code in a submodule the main repository can’t track your changes and commit. The module changes are considered “dirty”. So you need to step into the submodule and commit and push your changed code.