Select Page

Merging Two Git Repositories Into One Repository Without Losing File History

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.

  1. Create a new empty repository New.
  2. Make an initial commit because we need one before we do a merge.
  3. Add a remote to old repository A.
  4. Merge A/master to New/master.
  5. Make a subdirectory folderA.
  6. Move all files into subdirectory folderA.
  7. Commit all of the file moves.
  8. Repeat 3-6 for another repository.
 mkdir result cd result git init touch README.MD git add . git commit -m "added"

Step 3 to 6

 git remote add -f A 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”

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.