gitbutlerapp/gitbutler · error
Ambiguous branch '{branch_id}', matches multiple items
Error message
Ambiguous branch '{branch_id}', matches multiple items What it means
Short CLI IDs are prefixes into the workspace IdMap. When one prefix matches more than one entity, `but land` refuses to guess and bails with 'Ambiguous branch' (land/mod.rs:47-49); you must disambiguate before the command can proceed.
Source
Thrown at crates/but/src/command/legacy/land/mod.rs:48
let mut guard = ctx.exclusive_worktree_access();
{
let (_repo, ws, _db) = ctx.workspace_and_db_with_perm(guard.read_permission())?;
if !ws.kind.has_managed_ref() {
bail!(
"`but land` requires an active GitButler workspace (`gitbutler/workspace`). \
Switch into the workspace and try again."
);
}
}
let id_map = IdMap::new_from_context(ctx, guard.read_permission())?;
let resolved_ids = id_map.parse_using_context(branch_id, ctx)?;
if resolved_ids.is_empty() {
bail!("Could not find branch: {branch_id}");
}
if resolved_ids.len() > 1 {
bail!("Ambiguous branch '{branch_id}', matches multiple items");
}
let branch_name = match &resolved_ids[0] {
CliId::Branch(branch) => branch.name.clone(),
other => bail!("Expected a branch ID, got {}", other.kind_for_humans()),
};
let base_branch =
but_api::legacy::virtual_branches::get_base_branch_data(ctx, guard.write_permission())?
.ok_or_else(|| anyhow::anyhow!("No base branch configured"))?;
(branch_name, base_branch)
};
// Display strings for the prompt and the final report. The API recomputes the target/remote
// configuration internally; the CLI only needs these names to describe what's about to happen.
let target_branch_name = base_branch.short_name.clone();
let push_remote_name = if base_branch.push_remote_name.is_empty() {
base_branch.remote_name.clone()View on GitHub (pinned to caf1f223d3)
Solutions
- Add more characters to the ID until it is unique (verify in `but status`).
- Use the full branch name instead of the short ID.
- In scripts, resolve the full ID once and store that, rather than reusing brittle prefixes.
Example fix
# before but land 1 # '1' matches several entities -> Ambiguous branch # after but land 1a3 --yes # longer, unique prefix but land my-branch --yes
Defensive patterns
Strategy: validation
Validate before calling
# Cheap uniqueness check before running: count matches of the prefix in status output
count=$(but status | grep -cF '<id>')
[ "$count" -eq 1 ] || { echo 'ambiguous id'; exit 2; } Prevention
- Lengthen prefixes until unique; prefer full branch names in automation.
- Refresh IDs after history-rewriting operations (rebase, squash, amend).
When it happens
Trigger: `but land <prefix>` where the prefix is also a prefix of two or more IDs — e.g. single-character prefixes like `1` or `b` in a workspace with many branches, commits, and uncommitted files.
Common situations: Copy-truncated IDs; workspaces that grew so previously-unique short prefixes now collide; scripts reusing a hardcoded prefix that was unique when written.
Related errors
- Could not find branch: {branch_id}
- Expected a branch ID, got {}
- Commit ID '{commit_id_str}' is ambiguous. Please provide mor
- No branch found for ID: {branch_id}
- Refusing to directly update {target_display} without confirm
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/52177ca3914d8a76.
Report an issue: GitHub.