gitbutlerapp/gitbutler · error · anyhow::Error
Stack name '{stack}' is ambiguous in the current workspace
Error message
Stack name '{stack}' is ambiguous in the current workspace What it means
In `resolve_stack_id()`, after finding a first stack whose branch name matches, a second distinct match means the same name occurs in multiple stacks — unapply needs a unique target, so the command refuses. Matching compares full and shortened ref names per segment, so `main` matches both `refs/heads/main` and any other stack whose segment shortens to `main`.
Source
Thrown at crates/but-debug/src/command/api.rs:89
|| ref_name.shorten().as_bstr() == name.as_bytes()
})
})
}
if let Ok(stack_id) = stack.parse::<StackId>() {
return Ok(stack_id);
}
let (_guard, _repo, workspace, _db) = ctx.workspace_and_db()?;
let mut matches = workspace.stacks.iter().filter_map(|workspace_stack| {
stack_matches(workspace_stack, stack)
.then_some(workspace_stack.id)
.flatten()
});
let Some(stack_id) = matches.next() else {
bail!("Could not resolve stack '{stack}' by UUID or workspace branch name");
};
if matches.next().is_some() {
bail!("Stack name '{stack}' is ambiguous in the current workspace");
}
Ok(stack_id)
}
View on GitHub (pinned to caf1f223d3)
Solutions
- Use the stack UUID instead of the name — it bypasses name matching entirely.
- Use the fully qualified ref (`refs/heads/<branch>`) if only one stack carries the full name.
- Remove or rename the duplicate stack/branch so names become unique.
- Run `but api branch-list` to see which stacks collide on the name.
Example fix
# before but api unapply-stack main # two stacks have a segment shortening to 'main' # after but api branch-list # copy the intended stack's UUID but api unapply-stack 550e8400-e29b-41d4-a716-446655440000
Defensive patterns
Strategy: validation
Validate before calling
# Shell — count matches before unapply; require exactly one grep -c "name: <branch>" <(but api branch-list) # must print 1
Prevention
- Default to UUIDs in scripts to sidestep name ambiguity entirely.
- Use fully qualified ref names when names could repeat across stacks.
- Clean up duplicate stacks (from sync/recovery events) as soon as branch-list shows the same name twice.
When it happens
Trigger: Two workspace stacks each containing a segment whose ref name shortens to the same branch name (e.g. the same branch attached to two stacks, or identically named branches in different remotes/segments) while resolving by name instead of UUID.
Common situations: A branch detached from one stack and attached to another leaving both in the workspace; duplicated stacks from recovery/sync operations; user assuming short names are unique.
Related errors
- Could not resolve stack '{stack}' by UUID or workspace branc
- Commit ID '{}' is ambiguous. Found {} matches
- CLI id '{short_id}' is ambiguous for {kind} in IdMap
- Failed to parse diff header
- No stack selected!
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/85f579c265b84bb3.
Report an issue: GitHub.