For this you need git-filter-repo
installed (filter-branch is discouraged).
cd a
git filter-repo --to-subdirectory-filter a
cd ..
cd b
git remote add -f a ../a
git merge --allow-unrelated-histories a/master
git remote remove a
git remote add -f a ../a
being equivalent to:
git remote add a ../a
git fetch a
An example of merging 2 big repositories, putting one of them into a subdirectory: https://gist.github.com/x-yuri/9890ab1079cf4357d6f269d073fd9731
How do you merge two Git repositories?
Merge two Git repositories without breaking file history
Merge bundler into rubygems repo
Understanding Git Filter-branch and the Git Storage Model
Integrating a submodule into the parent repository
Just what I was looking for, thank you!
Solutions based on subtree seemed to leave dangling commits so that
git log projectA/README.md
, even with--follow
, did not include commits from the original external repository ("projectA"). This solution preserves tracing history for merged files.