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 →
- 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
- In the monorepo:
git remote add svc-a ../svc-a-rewrite && git fetch svc-a. git merge svc-a/main --allow-unrelated-histories -m "Import svc-a".- 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.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerYour feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?IntermediateThe team argues about fast-forward merges versus merge commits on `main`. How do you settle it?BeginnerA teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?IntermediateBefore merging, you want to see exactly what the feature branch adds compared to `main`. Which commands?BeginnerHalfway through a merge you realise you pulled the wrong branch. How do you back out?Beginner