Merging two git repositories with history
I maintain a number of Drupal websites, most of which are managed in a multisite install. I use the same, big git repository for all of them, pushing versions to my production environment using a standard workflow.
Sometimes, however, a project begins in its own repository, which I then want to merge into the multisite repository. I could use submodules to similar effect, but the whole point here is to consolidate repositories, not just link them.
Drupal installations share a lot of basic code, save for site-specific themes, files and contributed modules. The question is, how to merge in only the unique stuff, plus any contrib modules we don't already have in the master project, all the while maintaining history?
If the directory structures of the repositories are the same, you could do a simple git merge -s ours, but what if you have a legacy CVS, svn or other directory structure above the drupal web root? In my case, the "source" repository was under public/, and the multisite repo under src/public/.
This write-up suggests moving the source repo under a new directory, then merging, but that step is actually unnecessary. Try:
git merge -s recursive -Xsubtree=src -Xours source/masterUsing a recursive conflict resolution scheme, we can tell git to prepend the source path with an arbitrary string to match the structures. By adding -Xours, we choose to keep the multisite install's copy of any common paths, like Drupal core.
I believe a similar approach could be applied to adding a subdirectory of one repository into another, after the source repository was pruned using git filter-branch, though I haven't tried yet.
