Is there an easier way to integrate a subdirectory of an existing repository into another repository than sparse checkouts + subtree merge?

I have an existing code base (fairly large, being worked on by about a dozen developers) with a structure much like


I would like to reuse most files beneath src/shared in a separate project, hosted in a separate Git repository – preferably in a subdirectory, something like


Now, ideally I could move that common code into a separate repository and then use Git submodules or Git subtree to include that common repository into both ourproject and myproject. However, ourproject is being worked on by a lot of people and I’d like it to remain the “main” source of the files such that others don’t have to adjust their workflow.

Hence, to implement this, I’m planning to use an intermediate repository which holds a sparse checkout of the ourproject repository (sparse in the sense that it only holds the src/shared subdirectory). I’ll then use a subtree merge of that intermediate directory into the myproject repository.

However, having this intermediate repository is inconvenient and requires additional work for keeping it in sync. Is there a way to maybe combine the two such that I can do a subtree merge which only considers files beneath certain directories? Maybe a combination of a subtree merge and something built on filter-branch?

Git Baby is a git and github fan, let's start git clone.