gitbutlerapp/gitbutler · error
Expected branch identifier, got
Error message
Expected branch identifier, got {}. Please use a branch name or branch CLI ID. What it means
The single matching CliId is neither a Branch nor a Worktree, so it cannot be converted to a branch name for pushing. The error reports the kind via kind_for_humans() and directs the user to a branch name or branch CLI ID.
Solutions
- Use a branch name: `but push <branch-name>`.
- List branches with `but branch list` and use a branch CLI ID.
- If you intended to push a commit, move it onto a branch first, then push that branch.
Example fix
// before but push 3f // after but push feature/login
Defensive patterns
Strategy: validation
Validate before calling
const item = resolveCliId(id);
if (item && item.kind !== 'branch' && item.kind !== 'worktree') {
throw new Error(`"${id}" is a ${item.kind}; pass a branch name or branch CLI ID`);
}
butPush(id); Try / catch
const out = await exec('but', ['push', id]);
if (out.code !== 0 && /Expected branch identifier, got/.test(out.stderr)) {
const kind = out.stderr.match(/got ([\w ]+)\./)?.[1];
console.error(`"${id}" is a ${kind ?? 'non-branch item'}, not a branch.`);
} Prevention
- Only pass branch or worktree identifiers to but push
- Distinguish commit IDs from branch IDs before invoking
- Default scripts to explicit branch names rather than generic CLI IDs
When it happens
Trigger: Passing a CliId that resolves to exactly one non-branch, non-worktree item (e.g. a commit) to `but push`; the match arm in resolve_branch_name falls through to the catch-all error.
Common situations: Using a commit's CLI ID with `but push`, mistaking a change/commit ID for a branch ID in stacked-workspace workflows.
Related errors
- Ambiguous branch identifier
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch ' ' not found. Available branches
- ' ' does not refer to a commit
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/1cb7e77f06af8648.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/push.rs:1140
"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())
}
_ => Err(anyhow::anyhow!(
"Expected branch identifier, got {}. Please use a branch name or branch CLI ID.",
cli_ids[0].kind_for_humans()
)),
}
}
fn get_available_branch_names(ctx: &Context) -> anyhow::Result<Vec<String>> {
let lanes = crate::legacy::workspace::applied_lanes_with_expensive_commit_info(ctx)?;
let mut branch_names = Vec::new();
for stack in lanes {
for branch in &stack.branches {
branch_names.push(branch.name.clone());
}
}
branch_names.sort();
branch_names.dedup();View on GitHub (pinned to 58e5313667)