I have two tightly related projects (A and B) which share some source code (S). Both of them will be released at the same time and released version should always use the same version of shared code. Shared code S will be changed reasonably often.
So, it will look sometime like this:
What is the best way to handle this with git (and/or some tools which use git)?
Here are my concerns:
As I understand one of canonical answers is "use git submodule". However, I read some criticism about this approach. I felt like it was more designed to shared libraries which rarely change.
Another approach which I read was using git subtree
And there are couple of less popular approaches: Repo, GitSlave
What would be the best approach to handle this type of code sharing?
A very simple solution would be to use three repositories: A, B, and S. The project repositories A and B would have a check in their Makefiles to verify that the developer is using the latest code pushed to the repository, e.g.
check:
git fetch /path/to/S master:tip
git branch --contains tip | grep -q master
The second line will have a non-zero return value if the developer has an old version of the shared repository. This will abort the compilation with an error. The developer can then go and pull the repository manually to proceed.
Instead of checking the master branch of S, you could also check for some other branch that is defined to be always the one the developers should be using.
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