
Merging Two Git Repositories Into One Repository Without Losing File History

There seems to be a lot of way to merge two #git repositories into one repository without losing file history. Here is another straightforward method.
This method do not use #submodules or #subtree merges. it uses regular merge operations.
- Create a new empty repository New.
- Make an initial commit because we need one before we do a merge.
- Add a remote to old repository A.
- Merge A/master to New/master.
- Make a subdirectory folderA.
- Move all files into subdirectory folderA.
- Commit all of the file moves.
- Repeat 3-6 for another repository.
mkdir result cd result git init touch README.MD git add . git commit -m "added readme.md"
Step 3 to 6
git remote add -f A https://github.com/A.git git fetch --all git merge --allow-unrelated-histories A/master mkdir folderA git mv -k * folderA git commit -m “moved A files into subdir folderA”