gitbutlerapp/gitbutler · error

Branch ' ' not found

Error message

Branch '{branch_name}' not found

What it means

`find_branch_oid` scans the workspace's branches looking for one whose name equals `branch_name`, returning its tip OID. If no branch matches after the scan, it bails with a not-found message. Callers `get_branch_commits` and `get_branch_commit_count` use it to enumerate a branch's commits for `but show --branch`-style output.

Solutions

  1. List available branches (`but branches` / `but log`) and re-run with the exact name.
  2. Recreate or restore the branch if it was deleted (`git branch <name> <sha>`), or show the commit directly by hash.
  3. For remote-only branches, create a local branch from it first, or reference a commit ID instead.

Example fix

// before
but show feature/auth  # branch deleted
// error: Branch 'feature/auth' not found
// after
but branches           # find real name
but show feat/auth     # or use a commit id
Defensive patterns

Strategy: validation

Validate before calling

let branches: Vec<String> = list_branch_names(); // e.g. from `but branches`
if !branches.iter().any(|b| b == branch_name) {
    eprintln!("branch '{branch_name}' not in workspace; pick one of: {}", branches.join(", "));
    std::process::exit(1);
}

Type guard

fn branch_exists(branches: &[Branch], name: &str) -> bool {
    branches.iter().any(|b| b.name == name)
}

Try / catch

match result {
    Err(e) if e.to_string().starts_with("Branch '") && e.to_string().ends_with("' not found") => {
        eprintln!("list branches with `but branches` and retry with the exact name");
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Calling `but show` with a branch name (or branch CliId delegating to `show_branch` with verbose commit stats) where the name does not exactly match any branch in the workspace — wrong spelling, deleted branch, or a remote-only branch not present in the workspace list.

Common situations: Typo'd branch name; branch was merged/deleted before running the command; referring to a remote branch (`origin/feature`) that only exists as a remote ref, not a workspace branch; casing mismatch.

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/d2b0fc20466280b3. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/show.rs:493

    if let Some(branch) = branches
        .iter()
        .find(|b| b.name.as_bytes() == branch_name.as_bytes())
    {
        return Ok(branch.head);
    }

    // Not found in list_branches, check stacks
    let stacks = crate::legacy::workspace::applied_stacks(ctx)?;

    for stack in &stacks {
        for branch in &stack.branches {
            if branch.name == branch_name {
                return Ok(branch.tip);
            }
        }
    }

    anyhow::bail!("Branch '{branch_name}' not found")
}

fn get_branch_commits(
    ctx: &Context,
    branch_name: &str,
    verbose: bool,
    id_map: &IdMap,
) -> Result<(Vec<BranchCommitInfo>, Option<BranchCommitInfo>)> {
    use gix::prelude::ObjectIdExt as _;

    let repo = ctx.repo.get()?;

    // Find the branch by name
    let branch_oid = find_branch_oid(ctx, branch_name)?;

    // Find merge base
    let guard = ctx.shared_worktree_access();
    let cli_id_for = |oid: gix::ObjectId| {

View on GitHub (pinned to 58e5313667)