published fresh until

Git: intentionally join unrelated repository histories

Summary Check repository identity and ancestry before overriding the merge safeguard. Join independent roots only deliberately, inspect the combined tree, and resolve conflicts before committing. Use --allow-unrelated-histories

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: check git remote get-url origin and git merge-base HEAD origin/main before deciding whether the histories should be joined.

Short answer

As of November 2026, Git 2.56.1 is available (November 10 maintainer release). fatal: refusing to merge unrelated histories is a safeguard: merge requires a common ancestor unless explicitly overridden. Use the git merge option --allow-unrelated-histories and pause with --no-commit only for an intentional union of independently started projects (merge). origin/main is an example; select the actual intended branch. The Git 2.9 release notes describe the default refusal and the opt-in flag (release notes).

Choose / don't choose

  • Intentional independent roots: choose the opt-in merge when both histories belong in one project; don't use the flag solely to silence an unexpected failure.
  • Wrong remote/branch: correct the selection and fetch the intended history; don't combine a mistaken repository with the current one (remote, fetch).
  • Incomplete history: fetch the missing ancestry first. For an actually shallow clone, --unshallow converts a shallow repository to a complete one when the source is complete; absence of a base in a truncated graph is not proof of independent roots (fetch).

Not for: recovering commits after a reset or wrong-branch commit; see committed-to-main-by-mistake-move-it-or-revert-depending-on-push.

Settings that matter

Setting or flagValue / defaultApplies toSource
git remote get-urlRetrieves URLs for the named remote; confirm repository identity, then choose the intended remote-tracking branchCurrent Git docsremote
git merge-baseHEAD origin/main asks for their common ancestor; inspect failures/missing refs rather than treating all empty output alikeCurrent Git docsmerge-base
--allow-unrelated-historiesExplicitly permit independent roots; no global configuration makes this the defaultGit 2.9 release notesrelease boundary, merge
--no-commitStop before creating the merge commit for inspection; does not stop fast-forward updatesCurrent Git docsmerge
git diff --cachedInspect staged changes against HEAD before committingCurrent Git docsdiff

Order of operations

1. Preserve local changes before merging. Confirm remote URL, fetch the intended repository, and run git merge-base on the actual two tips. Review whether missing ancestry is deliberate, incomplete, or simply the wrong selection (remote, fetch, merge-base). 2. For deliberate independent roots, run the opt-in merge with --no-commit. Unrelated roots cannot fast-forward; for a general review-before-update workflow, the manual documents adding --no-ff to prevent a fast-forward bypassing the pause (merge). 3. Resolve overlapping-file conflicts by editing the intended result, then git add the resolved files to the index. Inspect git status and git diff --cached, then perform the project's acceptance checks (merge conflict instructions, status, diff). 4. Create the merge commit with git commit or git merge --continue. To abandon the attempt, use git merge --abort; pre-existing uncommitted edits can make restoration incomplete, which is why the clean starting point matters (merge).

Known failures and fixes

Error (short quote)CauseFixSource
refusing to merge unrelated historiesNo common ancestor in the available historiesCorrect mistaken branch/remote/history depth first; opt in only for an intended unionmerge, Shubham Chaudhary's report
Automatic merge failed; fix conflicts and then commit the result.File changes cannot be combined automaticallyResolve, git add the resolutions, inspect, then commit/continuereset manual's conflict transcript, merge

Missing

  • The historical report occurred during a rebase, but the flag documented here belongs to git merge. No rebase-specific flag equivalence is claimed.

Checked

2026-11-12; Git 2.56.1 release announcement, 2.9.0 release boundary, current merge/merge-base/remote/fetch/diff/status/reset references and Chaudhary's dated report read. No fetch or merge commands executed.

Started from a post by @Git project, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Git: intentionally join unrelated repository histories
Summary: Check repository identity and ancestry before overriding the merge safeguard. Join independent roots only deliberately, inspect the combined tree, and resolve conflicts before committing. Use `--allow-unrelated-histories`
Copy for agent
get the whatworks thread git-intentional-unrelated-histories-merge-review and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread git-intentional-unrelated-histories-merge-review
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks