gitbutlerapp/gitbutler · error

Ambiguous branch identifier

Error message

Ambiguous branch identifier '{}'. Did you mean one of:
{}

What it means

Disambiguation failure in resolve_branch_name: the given branch identifier matched multiple branches (multiple CliId::Branch results). The error lists the candidate branch names so the user can supply a more specific identifier or the exact branch name.

Solutions

  1. Use the full branch name instead of the ambiguous short ID.
  2. Copy the complete CLI ID from `but log` / `but branch list` rather than abbreviating.
  3. Pick one of the branches listed in the error message.
  4. Disambiguate by adding more characters of the CLI ID.

Example fix

// before
but push ab
// after
but push feature/login
Defensive patterns

Strategy: validation

Validate before calling

const matches = listBranches().filter(b => b.cliId.startsWith(shortId));
if (matches.length !== 1) throw new Error(`Ambiguous id "${shortId}"; use full name`);
butPush(matches[0].name);

Try / catch

const out = await exec('but', ['push', id]);
if (out.code !== 0 && /Ambiguous branch identifier/.test(out.stderr)) {
  const candidates = out.stderr.split('one of:\n')[1];
  console.error(`Pick one explicitly:\n${candidates}`);
}

Prevention

When it happens

Trigger: Passing a short/partial identifier (e.g. a CliId prefix like `ab`) to `but push` when two or more branches in the workspace share that prefix, resolved in resolve_branch_name via cli_ids with multiple CliId::Branch entries.

Common situations: Short stacks with many branches assigned nearby CLI IDs, using abbreviated IDs copied incompletely, workspaces where several branches start with the same prefix.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/495ed22a29f8ee2f. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/push.rs:1121

                "Branch '{}' not found. Available branches:\n{}",
                branch_id,
                format_branch_suggestions(&available_branches)
            ));
        }
        return Ok(branch_id.to_string());
    }

    if cli_ids.len() > 1 {
        let branch_names: Vec<String> = cli_ids
            .iter()
            .filter_map(|id| match id {
                CliId::Branch(branch) => Some(branch.name.clone()),
                _ => None,
            })
            .collect();

        if !branch_names.is_empty() {
            return Err(anyhow::anyhow!(
                "Ambiguous branch identifier '{}'. Did you mean one of:\n{}",
                branch_id,
                format_branch_suggestions(&branch_names)
            ));
        } else {
            return Err(anyhow::anyhow!(
                "Identifier '{branch_id}' matches multiple non-branch items. Please use a branch name or branch CLI ID."
            ));
        }
    }

    match &cli_ids[0] {
        CliId::Branch(branch) => Ok(branch.name.clone()),
        CliId::Worktree { name, .. } => {
            let repo = ctx.repo.get()?;
            let branch = crate::utils::worktrees::worktree_branch(&repo, name.as_ref())?;
            Ok(branch.shorten().to_string())
        }

View on GitHub (pinned to 58e5313667)