There is a well-known instance of this in the Git repository itself, which is collectively known in the Git community as "the coolest merge ever" (after the subject line Linus Torvalds used in the e-mail to the Git mailinglist which describes this merge). In this case, the gitk
Git GUI which now is part of Git proper, actually used to be a seperate project. Linus managed to merge that repository into the Git repository in a way that
- it appears in the Git repository as if it had always been developed as part of Git,
- all the history is kept intact and
- it can still be developed independently in its old repository, with changes simply being
git pull
ed.
The e-mail contains the steps needed to reproduce, but it is not for the faint of heart: first, Linus wrote Git, so he probably knows a bit more about it than you or me, and second, this was almost 5 years ago and Git has improved considerably since then, so maybe it is now much easier.
In particular, I guess nowadays one would use a gitk submodule, in that specific case.