{"record":{"id":"05d79a73808c8870","repo":"jdx/mise","slug":"local-and-origin-histories-are-unrelated-use-a-fr","errorCode":null,"errorMessage":"local and origin histories are unrelated; use a fresh setup store to adopt origin, or reconcile the repositories explicitly with Git. Neither history was replaced","messagePattern":"local and origin histories are unrelated; use a fresh setup store to adopt origin, or reconcile the repositories explicitly with Git\\. Neither history was replaced","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/sync/graph.rs","lineNumber":31,"sourceCode":"    pub base: Option<String>,\n}\n\n#[derive(Debug)]\npub(crate) struct Candidate {\n    pub commit: String,\n    expected_local: Option<String>,\n    expected_remote: Option<String>,\n}\n\nimpl Heads {\n    pub(crate) fn read(repo: &HistoryRepo) -> Result<Self> {\n        let local = repo.ref_oid(HistoryRepo::HISTORY_REF)?;\n        let remote = repo.ref_oid(UPSTREAM_REF)?;\n        let base = match (&local, &remote) {\n            (Some(local), Some(remote)) => {\n                let bases = repo.merge_bases(local, remote)?;\n                if bases.is_empty() {\n                    bail!(\n                        \"local and origin histories are unrelated; use a fresh setup store to adopt origin, or reconcile the repositories explicitly with Git. Neither history was replaced\"\n                    );\n                }\n                // A criss-cross merge has shared ancestry but no unique base.\n                // It needs a merge commit, never an arbitrary fast-forward.\n                (bases.len() == 1).then(|| bases[0].clone())\n            }\n            _ => None,\n        };\n        Ok(Self {\n            local,\n            remote,\n            base,\n        })\n    }\n\n    /// Preparing a candidate does not advance a branch or write live files.\n    /// The caller must finish its complete application before adopting it.","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/sync/graph.rs#L13-L49","documentation":"`read` in the sync graph module fails when both the local history ref and the origin (upstream) ref exist but share no merge base — the two commit histories are completely unrelated. Adopting or publishing would silently discard one side's history, so the operation aborts leaving both histories intact.","triggerScenarios":"Calling `read` when `merge_bases(local, remote)` returns empty: two independently initialized setup stores were pushed/fetched to the same origin, or a remote was replaced with a fresh history.","commonSituations":"Re-initializing the setup store on one machine and pushing it; cloning a different store into a repo whose local history already exists; switching between distinct setup store remotes.","solutions":["Start from a fresh setup store to adopt the origin history (discarding local history after backing up files).","Reconcile manually with Git: graft or merge the histories explicitly, then update both refs.","Point the upstream ref at the correct remote that shares ancestry with the local history."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const local = await git.revParse(HISTORY_REF);\nconst remote = await git.revParse(UPSTREAM_REF);\nif (local && remote && (await git.mergeBase(local, remote)) === null) {\n  throw new Error(\"local and origin histories are unrelated; reconcile explicitly\");\n}","typeGuard":"function historiesAreRelated(bases: string[]): boolean {\n  return bases.length > 0;\n}","tryCatchPattern":"try {\n  await sync.pull();\n} catch (e) {\n  if (/histories are unrelated/.test(String(e))) {\n    // prompt the user: adopt origin fresh or reconcile manually\n  } else throw e;\n}","preventionTips":["Never re-initialize a setup store that shares an origin with other machines.","Clone the existing setup store instead of creating a fresh one.","Verify the upstream ref points at the intended shared remote before syncing."],"tags":["git","history","merge-conflict"],"backgroundTag":"unrelated-git-histories","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}