{"record":{"id":"2889371fb843624b","repo":"coleam00/Archon","slug":"worktree-at-worktreepath-belongs-to-a-different","errorCode":null,"errorMessage":"Worktree at ${worktreePath} belongs to a different clone (${worktreeIdentity.commonGitDir}). Remove it from that clone or use a different codebase registration.","messagePattern":"Worktree at (.+?) belongs to a different clone \\((.+?)\\)\\. Remove it from that clone or use a different codebase registration\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/git/src/worktree.ts","lineNumber":485,"sourceCode":"    ]);\n  } catch (error) {\n    throw new Error(\n      `Cannot verify worktree ownership at ${worktreePath}: ${(error as Error).message}`,\n      {\n        cause: error,\n      }\n    );\n  }\n  if (!worktreeIdentity.linkedWorktree) {\n    // Not a git-worktree pointer (e.g., submodule pointer, or malformed).\n    // We cannot confirm this is our worktree, so refuse adoption.\n    throw new Error(`Cannot adopt ${worktreePath}: .git pointer is not a git-worktree reference.`);\n  }\n\n  // Compare resolved common-directory paths: the primary checkout and every\n  // linked worktree share this Git identity, while separate clones differ.\n  if (resolve(worktreeIdentity.commonGitDir) !== resolve(expectedIdentity.commonGitDir)) {\n    throw new Error(\n      `Worktree at ${worktreePath} belongs to a different clone (${worktreeIdentity.commonGitDir}). ` +\n        'Remove it from that clone or use a different codebase registration.'\n    );\n  }\n}\n","sourceCodeStart":467,"sourceCodeEnd":491,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/git/src/worktree.ts#L467-L491","documentation":"verifyWorktreeOwnership compares the common git directory (commonGitDir) of the worktree and the expected repo. Linked worktrees of one clone share a common dir, while separate clones do not. A mismatch means the directory is a worktree of a different clone, so adoption is refused with instructions to detach it from that clone or register the right codebase.","triggerScenarios":"Calling findExisting/assertWorktreeOwnership where worktreePath is a valid linked worktree but was created from another clone of the same project (e.g. a clone at a different path, a bare repo, or another machine's checkout mounted here).","commonSituations":"Moving or renaming the main clone so registered paths no longer match; having two clones of the same repo and pointing a codebase registration at one while the worktree belongs to the other; restoring backups of a worktree without its parent clone.","solutions":["Run `git worktree remove <path>` from the clone that owns the worktree, then `git worktree add` it from the expected repo.","Update the codebase registration to point at the clone that actually owns the worktree (the one in the error's commonGitDir).","If the parent clone moved, prune stale worktree metadata (`git worktree prune`) and recreate the worktree from the current clone.","Delete the orphaned worktree and let Archon provision a fresh one from the registered repo."],"exampleFix":"// before: worktree belongs to /old/clone, expected repo is /srv/clone\ncd /old/clone && git worktree remove /srv/app\ncd /srv/clone && git worktree add /srv/app feat-branch","handlingStrategy":"validation","validationCode":"const wt = await getGitCheckoutIdentity(worktreePath);\nconst repo = await getGitCheckoutIdentity(expectedRepo);\nif (resolve(wt.commonGitDir) !== resolve(repo.commonGitDir)) {\n  throw new Error(`worktree belongs to clone ${wt.commonGitDir}, not ${expectedRepo}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await assertWorktreeOwnership(worktreePath, expectedRepo);\n} catch (e) {\n  if (e.message.includes('belongs to a different clone')) {\n    console.error('Detach from the owning clone and re-add from the expected repo');\n  } else throw e;\n}","preventionTips":["Keep one canonical clone per project and create all worktrees from it.","Update codebase registrations when the parent clone moves.","Run `git worktree prune` after clone moves or backup restores, then recreate worktrees."],"tags":["git","worktree","ownership","clone"],"backgroundTag":"worktree-clone-mismatch","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}