On more than one occasion, I have needed to merge a Git repository and its history into a subdirectory of a second Git repository.
In this post, I show how to merge a Git repo
email@example.com:PUP/puppet-roles.git (hereafter “puppet-roles”) into the
modules/ directory a second Git repo
firstname.lastname@example.org:PUP/control-repo.git (“control-repo”). And after the merge, I show how to filter the history so that commands like
git blame and
git show all work as expected, and show a history as if the files in the subdirectory had always been there.
Set up a test environment
We begin by cloning control-repo into
/var/tmp as follows:
$ cd /var/tmp $ git clone email@example.com:PUP/control-repo.git