{"record":{"id":"c2dd313f5f0af98b","repo":"gitbutlerapp/gitbutler","slug":"non-main-worktrees-are-not-supported","errorCode":null,"errorMessage":"non-main worktrees are not supported","messagePattern":"non-main worktrees are not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-project/src/project.rs","lineNumber":327,"sourceCode":"            AddProjectOutcome::Added(p) => p,\n            _ => panic!(\"called `AddProjectOutcome::unwrap_project()` on a non-project outcome\"),\n        }\n    }\n\n    /// Try to get the `Project`, returning an error if it was not added.\n    pub fn try_project(self) -> anyhow::Result<Project> {\n        match self {\n            AddProjectOutcome::Added(p) => Ok(p),\n            AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!(\"project already exists\")),\n            AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!(\"project path not found\")),\n            AddProjectOutcome::NotADirectory => {\n                Err(anyhow::anyhow!(\"project path is not a directory\"))\n            }\n            AddProjectOutcome::BareRepository => {\n                Err(anyhow::anyhow!(\"bare repositories are not supported\"))\n            }\n            AddProjectOutcome::NonMainWorktree => {\n                Err(anyhow::anyhow!(\"non-main worktrees are not supported\"))\n            }\n            AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!(\"no workdir found for repository\")),\n            AddProjectOutcome::NoDotGitDirectory => {\n                Err(anyhow::anyhow!(\"no .git directory found in repository\"))\n            }\n            AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(\n                \"unsupported repository reference format: reftable\"\n            )),\n            AddProjectOutcome::NotAGitRepository(msg) => {\n                Err(anyhow::anyhow!(\"not a git repository: {msg}\"))\n            }\n        }\n    }\n}\n","sourceCodeStart":309,"sourceCodeEnd":342,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-project/src/project.rs#L309-L342","documentation":"try_project maps AddProjectOutcome::NonMainWorktree to this error. The directory is a valid git worktree but not the main one (a linked worktree created via `git worktree add`), which GitButler does not support for project management.","triggerScenarios":"Adding a directory created with `git worktree add <path> <branch>`, or a worktree whose `.git` is a file pointing back to the main repository's worktrees metadata.","commonSituations":"Developers using multiple checkouts of one repo, adding a feature-branch worktree folder, or pointing GitButler at a CI checkout directory.","solutions":["Add the main repository directory (the one containing the full `.git` directory, not a `.git` file).","Find the main worktree: run `git worktree list` inside the folder and use the entry marked (bare) main/first row's path.","If you only need this branch, open the main worktree in GitButler and manage the branch there via virtual branches instead."],"exampleFix":"// before\nlet project = add_project(worktree_path)?.try_project()?;\n// after\nlet git_meta = worktree_path.join(\".git\");\nif git_meta.is_file() {\n    // linked worktree: use the main worktree instead\n    return Err(\"add the main worktree, not a linked one\".into());\n}\nlet project = add_project(worktree_path)?.try_project()?;","handlingStrategy":"validation","validationCode":"fn is_main_worktree(path: &std::path::Path) -> bool {\n    // linked worktrees have a .git FILE pointing at the main repo\n    let git = path.join(\".git\");\n    git.is_dir()\n}","typeGuard":null,"tryCatchPattern":"match outcome.try_project() {\n    Err(e) if e.to_string() == \"non-main worktrees are not supported\" => {\n        // resolve main worktree via `git worktree list` and add that\n        add_main_worktree(&path)?;\n    }\n    other => other,\n}","preventionTips":["Run `git worktree list` and add the main (first) worktree path.","Avoid registering `git worktree add` output directories in GitButler.","Educate the team: manage alternate branches via virtual branches in the main worktree."],"tags":["git","project","worktree","unsupported"],"backgroundTag":"non-main-worktree-unsupported","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"}