Consider the following scenario:
Remote repo A (master):
dir 1
dir 2
file 1
file 2
Remote repo B (branch):
dir 1
file 1
What I'd like to do is to keep the common files in the two repos in sync. When I pull, I want to get all changes from Repo B
and only changes from the common files from Repo A
. Similarly, when I push, I want the local changes to be published only to common files in both repos. Files that exist in repo A but not in repo B should remain unaffected.
Does Git support this?
After hours of research, I decided to go with git subtree merging. Not git subtree
, which is a git contrib tool (talk about jargon overloading) but the strategy Git - Subtree Merging. The reasons behind my decision are as follows:
The Web is full of warnings against using git submodule. More importantly, for me, it is absolutely necessary to keep physical copies of the common files in both repos and not just a pointer to the remote repo. I also want the ability to update code from either the main or the subtree which submodule does not offer as well. So git submodule is out.
The git subtree tool looks nice and has a lot of followers but on close inspection, it seems to be very similar to the subtree merging strategy (in fact, someone said it is a nice decorator around subtree merging). It has a few additional features like the ability to squash subtree history while merging but that comes at the cost of learning a new method to push code. Plus, it is not part of the standard git binary yet (Git 10.8.4.2 on Mac, prebuilt binary) and I don't want to hand-install an upgrade every time there's a bug fix released.
Thank you those who've taken the time to answer my question, especially @dekdev, who tried to help me on the chat as well.