Suppose I have a repo parent
and a repo child
, where the latest is a submodule of the first one.
My child
repo is being maintained by a third party. I would like to keep track of the most recent updates made by this third-party while also doing my own specific changes to this submodule to make it compatible with my parent repo.
What is the proper way to do this?
This may not be the most elegant way to use submodules, but I have this exact situation and I handle it by cd
-ing into the submodule and handling it from there as a classic Git repo.
This way, it is easy to set my own fork of the child
project as origin
and the original child
project as upstream
. I can pull from upstream
to get the latest updates from the original project (maintained by a third party), make my own changes and push them to origin
so that they can be shared.
To update the parent
repo, I simply stage and commit the changes to the submodule.
In order to know what changes were made to the submodule from the parent
project when I commit those changes, I have, in my git config file:
[diff]
submodule = log
This will show the log of the submodule when running diff operations from within the parent
project. It is not necessary, but it is convenient as I don't have to go down to the submodule to know what I have done, etc.
You can set this locally by running git config diff.submodule log
from your parent
repo or you can set it globally with git config --global diff.submodule log
.
Note that you get the same result by running git diff --submodule
from your parent repo instead of git diff
(if you don't want to play with your config files).