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.
Those are separate teams.
Users ofB
don't need to have access to my repoC
, which they'd need if I make a submodule.
Similarly, users ofA
shouldn't have access toB
.
The fact that the code is shared across two separate repos need to be transparent to the current users of the repos. They can work on their individual repos, but not both.
Then you need to some kind of automatic hook which:
A
or B
check what are the common files That supposes that:
A
and B
servers (where TeamA
and TeamB
are pushing to) post-receive
hook Note: in order to protect access to both repos (or even files within a repo), and authorization layer like gitolite can help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.