Working in a Git repository that has Submodule(s)

Amila Kalansooriya
1 min readSep 15, 2018

Working in a sub-module is like working in any other git repository. Any git command that you perform inside a sub-module directory are executed in the context of that sub-repository. Sub modules too can have different branches, different log history, etc separated from the parent repository.

Editing the sub-module’s content and updating its repository

Lets say you want to change a tiny bit in a Sub-module. CD to the sub-module directory. Edit a file in the sub-module and change the working directory back to the main repository. Run git status. When you run ‘git status’ notice that it shows there are un-committed changes in the sub-module:

modified: styles/module (modified content)

When a module contains some uncommitted changes, so it is considered dirty. You must make sure to always keep a clean state in your sub-modules.

Now, change the working directory back to the sub-module:
cd path/to/submodule

Add your changes to the staging, commit them and push to the remote:

git commit -am "colour change"
git push origin BranchName

Whenever you try to commit any changes …

Kindly checkout https://www.geekgong.com/working-in-a-git-repository-that-has-submodules/ for the rest of this article.

Thanks.

--

--

Amila Kalansooriya

Thinker, Scholar, Teacher, problem solver, and a self-made web developer