{"record":{"id":"26b98f8a8787674e","repo":"gitbutlerapp/gitbutler","slug":"but-setup-cannot-run-from-a-linked-worktree-run-it-from-the","errorCode":null,"errorMessage":"`but setup` cannot run from a linked worktree; run it from the main worktree{}","messagePattern":"`but setup` cannot run from a linked worktree; run it from the main worktree(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":192,"sourceCode":"                anyhow::bail!(\n                    \"No git repository found - run `but setup --init` to initialize a new repository.\"\n                );\n            }\n        }\n    }\n}\n\n// setup a gitbutler project for the repository at `repo_path`\npub(crate) fn repo(\n    ctx: &mut Context,\n    repo_path: &Path,\n    out: &mut OutputChannel,\n    perm: &mut RepoExclusive,\n) -> anyhow::Result<()> {\n    let discovered = gix::discover(repo_path)?;\n    if discovered.git_dir() != discovered.common_dir() {\n        let main_worktree = discovered.main_repo()?;\n        anyhow::bail!(\n            \"`but setup` cannot run from a linked worktree; run it from the main worktree{}\",\n            main_worktree\n                .workdir()\n                .map(|dir| format!(\" at {}\", dir.display()))\n                .unwrap_or_default()\n        );\n    }\n    let t = theme::get();\n    let mut target_info: Option<TargetInfo> = None;\n\n    // what branch is head() pointing to?\n    let pre_head_name = {\n        let repo = ctx.repo.get()?;\n        let pre_head = repo.head()?;\n        pre_head\n            .referent_name()\n            .map(|n| n.shorten().to_string())\n            .unwrap_or_default()","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L174-L210","documentation":"`but setup` (project initialization in `repo()`) discovers the repository with `gix::discover` and refuses to proceed when the discovered git dir differs from the common dir, i.e. the path is a linked worktree (`git worktree add`). GitButler project setup must run from the main worktree; the error appends the main worktree path when it can be resolved.","triggerScenarios":"Running `but setup` while the current directory is a linked worktree created via `git worktree add`, pointing `-C` at a linked-worktree path, or scripting setup inside a per-worktree CI checkout.","commonSituations":"Developers using git worktrees for parallel branches who run setup from the wrong checkout; monorepo tooling that materializes linked worktrees; automation that picks the first directory found without checking it is the main worktree.","solutions":["cd to the main worktree (path shown in the error message) and run `but setup` there","Find the main worktree with `git worktree list` (the entry without a `worktree` annotation is main)","Remove the linked worktree if unneeded (`git worktree remove <path>`) and set up from main"],"exampleFix":"// before\ncd ~/repo-feature-x   # linked worktree\nbut setup\n\n// after\ngit worktree list\ncd ~/repo             # main worktree\nbut setup","handlingStrategy":"validation","validationCode":"# only run setup from the main worktree\ngit_dir=$(git rev-parse --git-common-dir)\nwork_dir=$(git rev-parse --git-dir)\n[ \"$git_dir\" = \"$work_dir\" ] || { echo \"linked worktree; run from main\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match setup_result {\n    Err(e) if e.to_string().starts_with(\"`but setup` cannot run from a linked worktree\") => {\n        // parse \" at <path>\" suffix and switch to main worktree\n        let main = parse_main_path(&e.to_string());\n        std::env::set_current_dir(main)?;\n        return setup_again();\n    }\n    other => other,\n}","preventionTips":["Check `git rev-parse --git-dir` vs `--git-common-dir` before setup","Use `git worktree list` to identify the main worktree","Restrict `but setup` to bootstrap scripts that run in the primary checkout","Avoid triggering setup from per-worktree automation"],"tags":["cli","git","worktree","setup","unsupported-operation"],"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"}