gitbutlerapp/gitbutler · error
No branch found for ID
Error message
No branch found for ID: {branch_id} What it means
`get_branch_names` converts a user-supplied CliId into branch names but can only map IDs of the `CliId::Branch` variant. If every ID in the collection maps to something else (commit, file, workspace, etc.) or is empty, there is no branch behind the given `branch_id`, so it bails naming the ID. This is an ID-to-entity resolution failure in the review pipeline.
Solutions
- Run `but status` to get current valid branch CliIds and use one that maps to a real branch
- Pass the branch name directly instead of a CliId if the command supports it
- Check that the branch still exists and hasn't been deleted or fully merged
- Refresh IDs after any rebase, push, or stack operation before creating a review
Example fix
null
Defensive patterns
Strategy: type-guard
Validate before calling
let branch_ids: Vec<_> = resolve_ids(ctx, &cli_id)?
.into_iter()
.filter(|id| matches!(id, CliId::Branch(_)))
.collect();
if branch_ids.is_empty() {
bail!("{cli_id} is not a branch; run `but status` for a valid branch ID");
} Type guard
fn is_branch_id(ids: &[CliId]) -> bool {
ids.iter().any(|id| matches!(id, CliId::Branch(_)))
} Try / catch
match create_review(..., cli_id, ...) {
Err(e) if e.to_string().starts_with("No branch found for ID") => {
eprintln!("ID does not refer to a branch; refresh with `but status`");
}
other => other?,
} Prevention
- Always fetch fresh CliIds from `but status` right before use — never cache them across operations
- Validate that the ID kind matches the expected entity (branch vs commit vs file) before passing it
- Re-resolve IDs after any rebase, push, or stack mutation
When it happens
Trigger: Calling `create_review` with a CliId that does not refer to a branch — e.g. passing a commit or file ID — or the referenced stack entry resolved to zero branch IDs (deleted/merged branch, stale ID after a rebase).
Common situations: User passes an ID copied from an older `but status` output after the branch was rebased/deleted; passing a commit ID instead of a branch ID to `but review`; automation scripts using stale CliIds.
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
- Branch ' ' not found when checking for conflicts
- Branch ' ' not found. Available branches
- Cannot apply non-existing branch
- Cannot unapply non-existing branch
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e2834edcaa28e60c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/forge/review.rs:469
}
}
Ok(branches_without_prs)
}
fn get_branch_names(project: &Project, branch_id: &str) -> anyhow::Result<Vec<String>> {
let ctx = Context::new_from_legacy_project(project.clone())?;
let id_map = IdMap::legacy_new_from_context(&ctx)?;
let branch_ids = id_map
.parse_using_context(branch_id, &ctx)?
.iter()
.filter_map(|clid| match clid {
CliId::Branch(branch) => Some(branch.name.clone()),
_ => None,
})
.collect::<Vec<_>>();
if branch_ids.is_empty() {
anyhow::bail!("No branch found for ID: {branch_id}");
}
Ok(branch_ids)
}
#[expect(clippy::too_many_arguments)]
pub async fn handle_multiple_branches_in_workspace(
ctx: &mut Context,
review_map: &std::collections::HashMap<String, Vec<but_forge::ForgeReview>>,
applied_stacks: &[HeadInfoStack],
skip_force_push_protection: bool,
with_force: bool,
run_hooks: bool,
default_message: bool,
draft: bool,
message: Option<&ForgeReviewMessage>,
out: &mut OutputChannel,
selected_branches: Option<Vec<String>>,View on GitHub (pinned to 58e5313667)