gitbutlerapp/gitbutler · error
Worktree has a workspace ref checked out, so there is no…
Error message
Worktree {name} has a workspace ref checked out, so there is no branch to commit to What it means
`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.
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.
Example fix
// before but commit --worktree gitbutler # workspace ref checked out // after but commit --worktree feature-wt # worktree with a real branch
Defensive patterns
Strategy: validation
Validate before calling
let head = repo.head_name()?;
if (head.includes('gitbutler/workspace')) throw new Error('pick a worktree with a regular branch, not the workspace worktree'); Type guard
fn is_plain_branch(r: &gix::refs::FullName) -> bool {
!but_core::is_workspace_ref_name(r.as_bstr())
} Try / catch
match worktree_branch(repo, name) {
Err(e) if e.to_string().contains("workspace ref") => {
eprintln!("{name} is the managed workspace; choose a branch worktree or use the workspace commit flow");
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- `but setup` cannot run from a linked worktree; run it from…
- Cannot currently work in repositories without a worktree
- Cannot currently work in repositories without a worktree
- Cannot hash directory entries that aren't files or symlinks
- Cannot restore branch
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/b6bfa74d4b9f934c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/utils/worktrees.rs:26
utils::{change_source::ChangeSourceId, targeting::Side},
};
/// The branch checked out in the linked worktree `name`, which is where a commit made from that
/// checkout goes and where a commit moved onto its lane lands.
///
/// A detached worktree has no branch to move, so it is refused rather than silently targeting
/// somewhere else. The same goes for a workspace ref: such worktrees never render a heading,
/// but the checkout can change between render and confirm, and a workspace ref must never
/// receive a commit meant for a branch.
pub(crate) fn worktree_branch(
repo: &gix::Repository,
name: &BStr,
) -> anyhow::Result<gix::refs::FullName> {
let worktree_repo = but_workspace::worktrees::open_worktree_repo(repo, name)?;
let branch = worktree_repo.head_name()?.with_context(|| {
format!("Worktree {name} has a detached HEAD, so there is no branch to commit to")
})?;
anyhow::ensure!(
!but_core::is_workspace_ref_name(branch.as_ref()),
"Worktree {name} has a workspace ref checked out, so there is no branch to commit to"
);
Ok(branch)
}
/// The tip an `--above`/`--below` argument naming the worktree `name` targets.
///
/// Below the heading is the top of its lane, so the tip of the branch checked out there. Above
/// it is the worktree's uncommitted area, which cannot hold a commit; `target_arg` is the
/// user's spelling of the worktree, for attributing that refusal.
pub(crate) fn worktree_tip_target(
repo: &gix::Repository,
name: &BStr,
side: Side,
target_arg: &CliIdArg,
) -> CliResult<gix::refs::FullName> {
match side {View on GitHub (pinned to 58e5313667)