Interview Prep/Git & GitHub/Branching and Merging Workflows

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 →

  1. Add the other repo as a remote and fetch it.
  2. Merge deliberately:
git remote add other ../other-repo
git fetch other
git merge other/main --allow-unrelated-histories
  1. 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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows