{"record":{"id":"ec544f17a5f7f468","repo":"gitbutlerapp/gitbutler","slug":"branch-branch-name-not-found-merge","errorCode":null,"errorMessage":"Branch {branch_name} not found","messagePattern":"Branch (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/land/merge.rs","lineNumber":39,"sourceCode":"    Merge {\n        oid: gix::ObjectId,\n        target_oid: gix::ObjectId,\n    },\n}\n\n/// Decide how to land `branch_name` onto the target and, for the merge case, build a signed,\n/// rename-aware merge commit. Conflicts bail here, before anything is pushed or moved.\npub(super) fn decide_land_outcome(\n    repo: &gix::Repository,\n    branch_name: &str,\n    fetch_remote_name: &str,\n    target_branch_name: &str,\n    no_ff: bool,\n) -> anyhow::Result<LandOutcome> {\n    let feature_ref_name = format!(\"refs/heads/{branch_name}\");\n    let feature_oid = repo\n        .try_find_reference(&feature_ref_name)?\n        .ok_or_else(|| anyhow::anyhow!(\"Branch {branch_name} not found\"))?\n        .into_fully_peeled_id()?\n        .detach();\n\n    let target_ref_name = format!(\"refs/remotes/{fetch_remote_name}/{target_branch_name}\");\n    let target_oid = repo\n        .try_find_reference(&target_ref_name)?\n        .ok_or_else(|| anyhow::anyhow!(\"Target branch {target_ref_name} not found\"))?\n        .into_fully_peeled_id()?\n        .detach();\n\n    // No common ancestor: refuse rather than merge two unrelated histories onto the target.\n    let Some(merge_base) = super::merge_base_opt(repo, feature_oid, target_oid)? else {\n        bail!(\n            \"Cannot merge {branch_name}: it shares no history with {fetch_remote_name}/{target_branch_name}\"\n        );\n    };\n\n    if merge_base == feature_oid {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/land/merge.rs#L21-L57","documentation":"`decide_land_outcome` resolves the feature branch by constructing `refs/heads/{branch_name}` and peeling it to an OID. If the repository contains no such reference, it throws \"Branch {branch_name} not found\". This is a pre-flight lookup in the land/merge path: without the feature ref's OID the merge-base/merge analysis cannot proceed.","triggerScenarios":"Calling the land/merge API with a `branch_name` that has no `refs/heads/<name>` reference in the repo — typically after the branch was deleted, never created, renamed, or when passing a branch that lives only in the virtual (GitButler-applied) workspace rather than as a real git branch.","commonSituations":"Landing a branch that was already merged and deleted; a typo'd or stale branch name in automation; running the operation on a clone that lacks the local branch; GitButler workspace stacks whose heads are not checked out as plain branches.","solutions":["Check the branch exists locally: `git branch --list <branch_name>`; create or fetch it if missing.","Use the exact current branch name from workspace/stack metadata instead of a cached one.","If the branch was already merged and deleted, skip landing — the outcome is already achieved.","Verify you are operating on the correct repository/workdir."],"exampleFix":"// before\nland_branch(\"feature-x\", ...); // may not exist\n// after\nif !repo.try_find_reference(&format!(\"refs/heads/feature-x\"))?.is_some() {\n    eprintln!(\"feature-x not found locally; fetching or skipping\");\n    return Ok(());\n}\nland_branch(\"feature-x\", ...);","handlingStrategy":"validation","validationCode":"// check the feature branch ref exists before landing\nif repo.try_find_reference(&format!(\"refs/heads/{branch_name}\"))?.is_none() {\n    return Err(anyhow::anyhow!(\"branch {branch_name} does not exist locally\"));\n}","typeGuard":null,"tryCatchPattern":"match land_outcome(branch) {\n    Err(e) if e.to_string().contains(\"not found\") =>\n        eprintln!(\"branch {branch} missing locally; fetch first or skip\"),\n    other => other?,\n}","preventionTips":["Use exact branch names from `but branch list` / workspace metadata","Fetch before landing so refs are current","Don't land branches that were already merged-and-deleted"],"tags":["git","branch-not-found","merge","rust"],"backgroundTag":"resource-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"}