{"record":{"id":"b6bfa74d4b9f934c","repo":"gitbutlerapp/gitbutler","slug":"worktree-name-has-a-workspace-ref-checked-out-s","errorCode":null,"errorMessage":"Worktree {name} has a workspace ref checked out, so there is no branch to commit to","messagePattern":"Worktree (.+?) has a workspace ref checked out, so there is no branch to commit to","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/utils/worktrees.rs","lineNumber":26,"sourceCode":"    utils::{change_source::ChangeSourceId, targeting::Side},\n};\n\n/// The branch checked out in the linked worktree `name`, which is where a commit made from that\n/// checkout goes and where a commit moved onto its lane lands.\n///\n/// A detached worktree has no branch to move, so it is refused rather than silently targeting\n/// somewhere else. The same goes for a workspace ref: such worktrees never render a heading,\n/// but the checkout can change between render and confirm, and a workspace ref must never\n/// receive a commit meant for a branch.\npub(crate) fn worktree_branch(\n    repo: &gix::Repository,\n    name: &BStr,\n) -> anyhow::Result<gix::refs::FullName> {\n    let worktree_repo = but_workspace::worktrees::open_worktree_repo(repo, name)?;\n    let branch = worktree_repo.head_name()?.with_context(|| {\n        format!(\"Worktree {name} has a detached HEAD, so there is no branch to commit to\")\n    })?;\n    anyhow::ensure!(\n        !but_core::is_workspace_ref_name(branch.as_ref()),\n        \"Worktree {name} has a workspace ref checked out, so there is no branch to commit to\"\n    );\n    Ok(branch)\n}\n\n/// The tip an `--above`/`--below` argument naming the worktree `name` targets.\n///\n/// Below the heading is the top of its lane, so the tip of the branch checked out there. Above\n/// it is the worktree's uncommitted area, which cannot hold a commit; `target_arg` is the\n/// user's spelling of the worktree, for attributing that refusal.\npub(crate) fn worktree_tip_target(\n    repo: &gix::Repository,\n    name: &BStr,\n    side: Side,\n    target_arg: &CliIdArg,\n) -> CliResult<gix::refs::FullName> {\n    match side {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/utils/worktrees.rs#L8-L44","documentation":"`worktree_branch` resolves the branch a worktree has checked out so commits can be routed to it. After getting the HEAD name, it ensures the ref is not a GitButler workspace ref (e.g. gitbutler/workspace); if it is, there is no plain branch to commit to and this error is thrown.","triggerScenarios":"Calling commit operations (route_commit_operation, worktree_branch_target, worktree_tip_target, CommitRelativeToTarget::BranchTip) against a worktree whose checked-out ref is the GitButler workspace ref rather than a regular branch.","commonSituations":"Targeting the main GitButler-managed worktree by name when intending a regular branch worktree; passing a worktree name that points at the integrated workspace instead of a feature stack; automation scripts iterating all worktrees including the workspace one.","solutions":["Target a worktree that has a regular branch checked out, not the GitButler workspace worktree.","List worktrees (`git worktree list` / but equivalent) and use the one whose HEAD is a normal branch.","If you meant to commit inside the managed workspace, use the workspace-specific commit flow instead of the per-worktree branch commit path.","Create a branch worktree: `git worktree add ../wt -b feature` and commit there."],"exampleFix":"// before\nbut commit --worktree gitbutler  # workspace ref checked out\n// after\nbut commit --worktree feature-wt  # worktree with a real branch","handlingStrategy":"validation","validationCode":"let head = repo.head_name()?;\nif (head.includes('gitbutler/workspace')) throw new Error('pick a worktree with a regular branch, not the workspace worktree');","typeGuard":"fn is_plain_branch(r: &gix::refs::FullName) -> bool {\n    !but_core::is_workspace_ref_name(r.as_bstr())\n}","tryCatchPattern":"match worktree_branch(repo, name) {\n  Err(e) if e.to_string().contains(\"workspace ref\") => {\n    eprintln!(\"{name} is the managed workspace; choose a branch worktree or use the workspace commit flow\");\n  }\n  other => other?,\n}","preventionTips":["List worktrees and verify each has a plain branch HEAD before scripting commits.","Skip refs matching the gitbutler/workspace namespace in automation loops.","Create dedicated branch worktrees for per-worktree commit flows."],"tags":["git","worktree","branching","invalid-state"],"backgroundTag":"invalid-state-transition","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"}