{"record":{"id":"d2b0fc20466280b3","repo":"gitbutlerapp/gitbutler","slug":"branch-branch-name-not-found","errorCode":null,"errorMessage":"Branch '{branch_name}' not found","messagePattern":"Branch '(.+?)' not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/show.rs","lineNumber":493,"sourceCode":"    if let Some(branch) = branches\n        .iter()\n        .find(|b| b.name.as_bytes() == branch_name.as_bytes())\n    {\n        return Ok(branch.head);\n    }\n\n    // Not found in list_branches, check stacks\n    let stacks = crate::legacy::workspace::applied_stacks(ctx)?;\n\n    for stack in &stacks {\n        for branch in &stack.branches {\n            if branch.name == branch_name {\n                return Ok(branch.tip);\n            }\n        }\n    }\n\n    anyhow::bail!(\"Branch '{branch_name}' not found\")\n}\n\nfn get_branch_commits(\n    ctx: &Context,\n    branch_name: &str,\n    verbose: bool,\n    id_map: &IdMap,\n) -> Result<(Vec<BranchCommitInfo>, Option<BranchCommitInfo>)> {\n    use gix::prelude::ObjectIdExt as _;\n\n    let repo = ctx.repo.get()?;\n\n    // Find the branch by name\n    let branch_oid = find_branch_oid(ctx, branch_name)?;\n\n    // Find merge base\n    let guard = ctx.shared_worktree_access();\n    let cli_id_for = |oid: gix::ObjectId| {","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/show.rs#L475-L511","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["List available branches (`but branches` / `but log`) and re-run with the exact name.","Recreate or restore the branch if it was deleted (`git branch <name> <sha>`), or show the commit directly by hash.","For remote-only branches, create a local branch from it first, or reference a commit ID instead."],"exampleFix":"// before\nbut show feature/auth  # branch deleted\n// error: Branch 'feature/auth' not found\n// after\nbut branches           # find real name\nbut show feat/auth     # or use a commit id","handlingStrategy":"validation","validationCode":"let branches: Vec<String> = list_branch_names(); // e.g. from `but branches`\nif !branches.iter().any(|b| b == branch_name) {\n    eprintln!(\"branch '{branch_name}' not in workspace; pick one of: {}\", branches.join(\", \"));\n    std::process::exit(1);\n}","typeGuard":"fn branch_exists(branches: &[Branch], name: &str) -> bool {\n    branches.iter().any(|b| b.name == name)\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"Branch '\") && e.to_string().ends_with(\"' not found\") => {\n        eprintln!(\"list branches with `but branches` and retry with the exact name\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Copy branch names from `but branches` output instead of typing them","Re-check that the branch wasn't deleted/merged before scripting against it","Use commit IDs for histories of branches that may disappear"],"tags":["git","branch","not-found","cli"],"backgroundTag":"entity-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}