gitbutlerapp/gitbutler · error

Branch ' ' not found. Available branches

Error message

Branch '{}' not found. Available branches:
{}

What it means

`but push <branch>` could not resolve the given identifier: it matched no CliId and is not a literal branch name in the workspace. The error lists the available branch names (via format_branch_suggestions) so the user can pick a valid one.

Solutions

  1. Run `but branch list` (or read the suggestions in the error) and use an exact existing branch name.
  2. Check for typos and case in the branch name.
  3. Use the branch's CLI ID shown by `but log`/`but branch list` instead of the name.
  4. Recreate or restore the branch if it was deleted (e.g. `git branch <name> <sha>`).

Example fix

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

Strategy: validation

Validate before calling

but branch list | grep -qx "$BRANCH" || { echo "branch '$BRANCH' not found"; exit 1; }
but push "$BRANCH"

Try / catch

const out = await exec('but', ['push', branch]);
if (out.code !== 0 && /not found\. Available branches:/.test(out.stderr)) {
  const suggestions = out.stderr.split('Available branches:\n')[1];
  console.error(`Branch "${branch}" does not exist. Options:\n${suggestions}`);
}

Prevention

When it happens

Trigger: Calling `but push <branch_id>` (or handle/handle_dry_run -> resolve_branch_name) with a typo'd branch name, a branch that was deleted/merged, or an identifier string that matches nothing in the id_map.

Common situations: Typing a branch name from memory, referencing a branch deleted after a stack rebase, running scripts against a stale branch list, case-sensitivity mismatches in branch names.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

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

        flags.push(but_gerrit::PushFlag::Private);
    }

    Ok(flags)
}

fn resolve_branch_name(
    ctx: &mut Context,
    id_map: &IdMap,
    branch_id: &str,
) -> anyhow::Result<String> {
    // Try to resolve as CliId first
    let cli_ids = id_map.parse_using_context(branch_id, ctx)?;

    if cli_ids.is_empty() {
        // If no CliId matches, treat as literal branch name but validate it exists
        let available_branches = get_available_branch_names(ctx)?;
        if !available_branches.contains(&branch_id.to_string()) {
            return Err(anyhow::anyhow!(
                "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() {

View on GitHub (pinned to 58e5313667)