I have two git repositories, A
and B
A
is a library that other projects love to use. It has only one branch master
.
In B
, I add A
as a submodule, and so it clones it into B
's directory. The HEAD
is NOT detached since I said to track branch master
when adding.
Inside my project B
, I notice a bug in A
's code. I change the code inside the submodule A
(the cloned code that lied inside of B
's directory). I now want to commit those changes I've made to A
from within B
commit them to the master branch of A
, leaving B
still with zero commits.
How can this be done?
Ex.
Projects
|---A # Existing repository. On branch master.
|---B # Repository just created.
git init
git submodule add -b master ../A
git submodule update --remote
cd A/
vi importantFile.txt # Here I make changes to internal files in A
# How do I now commit those changes and add a commit to A?
You can just execute the git command in the folder of the submodule and it will be applied to the submodule. You just have to make sure the master there is up to date and you are not in a detached head mode.
But in order to update the submodule for the main project (so if others checkout the main project with submodules, to the the updated version) you will definitely need a commit there to bump the version.
Further reading: Git commit to common submodule (master branch)