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
- 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.
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
- 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
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
- Branch ' ' not found when checking for conflicts
- Local branch ' ' not found
- Branch " " has no conflicted commits.
- Branch ' ' not found. Available branches
- Cannot apply non-existing branch
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)