Suppose we have the following repository structure on github:
company:project.git \- company:submodule.git
A developer in my company forks the company project, making his workspace look like this:
developer:project.git \- company:submodule.git
This is fine for 90% of the developers since they don't change the submodule library, they only work in the project. Now suppose there's a new feature which requires improvements in the submodule. The developer charged with this converts his workspace to this:
developer:project.git \- developer:submodule.git
Getting there is not trivial as he needs to replace a submdule with another submodule (to git, the original and the fork of the submodule are two different things).
If this developer works on the library for a bit longer, he commits this structure to his master branch, so his fork on github always uses the forked submodule.
Once he's ready with development, he'll create a pull request. The problem is that when merging the pull request the main repository will look like this:
company:project.git \- developer:submodule.git
This is problematic as now every developer that tracks the company branch will end up with the developer's submodule.
To workaround the problem, before the developer makes a pull request, his master branch should be moved back to the company:submodule.git - which is just very awkward, especially since locally he'll always still want to work with developer:submodule.git.
We've tried several workflows, and the above issue is the only one where we don't have a good workflow yet.
When the developer creates a commit with the submodule at a particular version, that's a strong statement that the supermodule works with the submodule at that exact version. If his code does actually work with the company's version of the submodule, I think the right thing to do is for the developer to:
.gitmodules
in the supermodule, if the developer changed that from the upstream versionHe can then switch back to his normal development branch in the supermodule.
One thing I don't understand about your question is the following:
Getting there is not trivial as he needs to replace a submdule with another submodule (to git, the original and the fork of the submodule are two different things).
On the contrary, the submodule can be any git repository so long as it contains the commit which the supermodule points to. If there are two different remote repositories, he can just add an extra remote in the submodule. (The developer should change .gitmodules
as well if they're going to share their repository with anyone else.)
In response to your comment below, perhaps it's worth going through how to switch a submodule from pointing to one version to another. Let's suppose that the developer is using their own repositories for the super and submodule, but those are both cloned from the company's versions (i.e. so most of the history is the same), and the submodule is at the path lib
. The developer now wants to switch the submodule to point to the company's version instead. They can do the following:
url
parameter for the submodule in .gitmodules
to point to the company's repository.cd lib
git remote add company developer@company:/srv/git/lib.git
git fetch company
git checkout -b upstream-master company/master
cd ..
git add .gitmodules lib
git commit -m "Switch the lib submodule to point back to the company's version"
Steps 3 to 5 can just be changed to git checkout <whatever>
once the remote and branch are set up.
Another, simple solution is to tell git to ignore .gitmodules and to remove them from tracking. As said above, .gitmodules are used only for initializing submodules, so it's needed only once, upon checking out the submodules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With