I found Using Git, what's the best way to subtree merge an external project that has submodules? but while related, it doesn't answer my question.
Suppose I have my Parent project and my Child project, which contains submodules. How do I subtree merge the Child project into a subdirectory of the Parent project and keep the references to the submodules working?
I've tried things like:
git remote add -f child_remote git://github.com/me/child.git
git checkout -b child_branch child_remote/master
git submodule init
git submodule update
git checkout master
git read-tree --prefix=child_directory/ -u child_branch
But read-tree loses the submodules, and .gitmodules appears only in the subdirectory. When I try to do git submodule init and git submodule update I get errors like "No submodule mapping found in .gitmodules for path 'child_directory/submodule_directory'".
I've also tried to modify the instructions at http://help.github.com/subtree-merge/ to work with submodules, but to no avail.
I understand that I could accomplish this by manually modifying the .gitmodules file to refer to the correct path, or merging in the Child project without submodules and then re-adding them to the Parent project, but I consider both of those solutions to be hacks. I'm looking for the actual commands one would run to get this to work automatically, without having to manually edit anything.