Ok, that is not a perfect setup, but should be good enough.
The idea is to have one branch in which everything apart from that subdirectory and common files is removed (I mean: don't exist at all), and to accept pull requests for that branch (you may create a new repository containign only that branch).
It is a bit twisted, so I'm going to show it through an example. Let's say, your project was created with commads like this:
mkdir bigproj
cd bigproj
git init
echo "common file" >common
mkdir subproj
echo "subproj content" >subproj/content
mkdir other
echo "other content" >other/content
git add common subproj other
git commit -m 'Initial commit'
git commit --allow-empty -m 'Some history'
It has a common
file inside, a subproj
subdirectory with some content, and the other
subdirectory with another content. Tree:
.
├── common
├── other
│ └── content
└── subproj
└── content
Now let's create a branch containing only common
and subproj
without history:
git checkout --orphan subproj-branch
git rm -rf . # clear the index
git checkout master -- common subproj # put `common` and `subproj` back to index
git commit -m 'Initial commit for subproj-branch'
Resulting tree:
.
├── common
└── subproj
└── content
Merge this branch back into master
to avoid possible false conflicts:
git checkout master
git merge subproj-branch # obviously no conflicts
Now we can publish subproj-branch
in some dedicated repository:
git remote add subproj-repo <some url>
git push subproj-repo subproj-branch:master --set-upstream # -f may be needed.
# And remote branch doesn't have to be named master, of course.
Repository is published, we got some patches. Now we can merge them:
git checkout subproj-branch
git pull
git checkout master
git merge subproj-branch
That is the base flow, which allows making changes in subproj-repo and incorporating them into main repository. Now, making it the other way around is a bit more problematic, but possible. There are to possibilities:
Changes touch only subproj
/common
. We may take them "as they are":
git checkout subproj-branch
git cherry-pick master # replace master with anything you actually need
git checkout master
git merge subproj-branch
git push subproj-repo subproj-branch:master
Changes touch both subproj
/common
and other files. You can manually checkout each changed file into subproj-branch
then commit and merge back to master (to avoid false conflicts in future). That is not perfect, and you may want to alter that step somehow.
git checkout subproj-branch
git checkout master -- common subproj
git commit -m 'Some changes'
git checkout master
git merge subproj-branch
git push subproj-repo subproj-branch:master
Important part here is merging changes back to master. That may seem nonsensical, but may prevent some conflicts from happening.
Whoa, that is a long answer. I hope it will be helpful :P