Interview Prep/Git & GitHub/Branching and Merging Workflows

You must combine two repositories into a monorepo and keep full history for both. How?

AdvancedScenarioBranching and Merging Workflows
Answer

Situation read → Copying files loses history and blame. We want a real merge.

What I'd do →

  1. In each source repo, rewrite history into a subdirectory (work on a fresh clone):
git clone svc-a svc-a-rewrite && cd svc-a-rewrite
git filter-repo --to-subdirectory-filter services/svc-a
  1. In the monorepo: git remote add svc-a ../svc-a-rewrite && git fetch svc-a.
  2. git merge svc-a/main --allow-unrelated-histories -m "Import svc-a".
  3. Repeat for the other repo, then archive the old repos.

Why → Rewriting paths first prevents file collisions and keeps git log -- services/svc-a and blame working.

Interview tip → Mention git subtree add as the simpler option when path-prefixed history is enough.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows