Member-only story

Merging Git repositories without losing history

--

I’m the first to admit that merging two repositories isn’t something that you would do often. On the other hand, I’ve seen my fair share of situations where teams were keeping separate repositories for their front-end SPA application and the accompanying back-end APIs and running into issues. Even though keeping them separate may give a sense of isolation, in reality you end up coordinating teams across those repos whenever a big feature needs to introduced. And don’t get me started on the challenges getting those HTTP APIs aligned. So moving to a mono-repo isn’t that uncommon after all.

With a bit of Git magic, it’s quite easy to merge the commits of one repository into a specific folder of another without losing the Git history. Here’s a high-level overview.

  1. Install git-filter-repo using the instructions Elijah Newren prepared on his repo.
  2. As the git filter-repo command is a destructive operation, clone the source repo to a safe location
  3. Determine the directory at which the code from the source repo should end up
  4. Determine the prefix you want to use to add to all tags from the source repo
  5. Run git filter-repo
  6. Add the modified working directory as a git remote to the target repository

--

--

Dennis "The Continuous Improver" Doomen
Dennis "The Continuous Improver" Doomen

Written by Dennis "The Continuous Improver" Doomen

Dennis is a veteran architect in the .NET space with a special interest in writing clean code, Domain Driven Design, Event Sourcing and everything agile.

No responses yet