{"record":{"id":"267adecb48e258d7","repo":"gitbutlerapp/gitbutler","slug":"the-repository-at-is-a-non-main-worktree-gitbu","errorCode":null,"errorMessage":"The repository at {} is a non-main worktree. GitButler requires the main worktree.","messagePattern":"The repository at (.+?) is a non-main worktree\\. GitButler requires the main worktree\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":265,"sourceCode":"                    \"  {}\",\n                    t.success.paint(\"✓ Repository already in project registry\")\n                )?;\n            }\n            Ok(ProjectStatus::AlreadyExists)\n        }\n        gitbutler_project::AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!(\n            \"The path {} does not exist\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::NotADirectory => Err(anyhow::anyhow!(\n            \"The path {} is not a directory\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::BareRepository => Err(anyhow::anyhow!(\n            \"The repository at {} is bare. GitButler requires a non-bare repository.\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::NonMainWorktree => Err(anyhow::anyhow!(\n            \"The repository at {} is a non-main worktree. GitButler requires the main worktree.\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!(\n            \"The repository at {} has no working directory. GitButler requires a working directory.\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::NoDotGitDirectory => Err(anyhow::anyhow!(\n            \"The repository at {} has no .git directory. GitButler requires a .git directory.\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(\n            \"The repository at {} uses the currently unsupported reftable reference format.\",\n            repo_path.display()\n        )),\n        gitbutler_project::AddProjectOutcome::NotAGitRepository(_) => Err(anyhow::anyhow!(\n            \"The path {} is not a git repository.\",\n            repo_path.display()","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L247-L283","documentation":"Worktree-kind validation during project setup (repo command): the path points at a linked (non-main) worktree of a repository, but GitButler only manages the main worktree. Run setup from the repository's main worktree directory instead.","triggerScenarios":"Running `but setup` inside a linked worktree created with `git worktree add <path>` instead of the original clone directory.","commonSituations":"Developers using `git worktree` for parallel branches pointing GitButler at the secondary worktree; automation that checks out worktrees into temp dirs.","solutions":["Run setup from the main worktree (the original clone directory).","If you need GitButler on this code, clone the repository fresh at this path.","Inspect `git worktree list` to identify the main worktree path."],"exampleFix":"// before\ncd ~/repo-feature-branch-worktree && but setup\n// after\ncd ~/repo && but setup","handlingStrategy":"validation","validationCode":"const main = await run(['git', '-C', repoPath, 'rev-parse', '--path-format=absolute', '--git-common-dir']);\nconst toplevel = await run(['git', '-C', repoPath, 'rev-parse', '--show-toplevel']);\n// linked worktrees have a git-common-dir outside <toplevel>/.git","typeGuard":"function isMainWorktree(p: string): boolean {\n  const r = cp.spawnSync('git', ['-C', p, 'rev-parse', '--git-dir']);\n  return r.status === 0 && r.stdout.toString().trim() === '.git';\n}","tryCatchPattern":"try {\n  await run(['but', 'setup', repoPath]);\n} catch (e) {\n  if (String(e).includes('non-main worktree')) {\n    console.error('Run but setup from the main worktree (see: git worktree list).');\n  }\n  throw e;\n}","preventionTips":["Check `git worktree list` to find the main worktree before setup.","Register the original clone with GitButler, not linked worktrees.","Avoid automation that checks out linked worktrees into temp dirs for setup."],"tags":["git","worktree","cli","setup"],"backgroundTag":"unsupported-operation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}