You need to merge a repo that has no common history with yours. Git refuses. What now?
IntermediateScenarioBranching and Merging Workflows
Answer
Situation read → fatal: refusing to merge unrelated histories appears because the two repos have no shared ancestor.
What I'd do →
- Add the other repo as a remote and fetch it.
- Merge deliberately:
git remote add other ../other-repo
git fetch other
git merge other/main --allow-unrelated-histories
- Resolve add/add conflicts (README, .gitignore), then commit.
Why → The safety check exists to stop accidental merges of the wrong repo. The flag is an explicit confirmation.
Interview tip → For a cleaner layout, first move the other repo's files into a subdirectory with git filter-repo --to-subdirectory-filter.
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