{"record":{"id":"d9b4c4d5d8da5b59","repo":"gitbutlerapp/gitbutler","slug":"target-branch-target-ref-name-not-found","errorCode":null,"errorMessage":"Target branch {target_ref_name} not found","messagePattern":"Target branch (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/land/merge.rs","lineNumber":46,"sourceCode":"/// 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 {\n        return Ok(LandOutcome::AlreadyIntegrated);\n    }\n    if merge_base == target_oid && !no_ff {\n        return Ok(LandOutcome::FastForward {\n            feature_oid,\n            target_oid,\n        });","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/land/merge.rs#L28-L64","documentation":"`decide_land_outcome` resolves the merge target as the remote-tracking ref `refs/remotes/{fetch_remote_name}/{target_branch_name}` and throws this error when that reference does not exist. The land operation intentionally merges onto the remote-tracking state, so the target branch must exist on the configured fetch remote.","triggerScenarios":"Calling the land/merge API when the repo has never fetched the target branch from `fetch_remote_name` (no `refs/remotes/<remote>/<target>` ref); the remote name is wrong; the branch does not exist upstream; or the target is configured as a local-only branch with no remote tracking ref.","commonSituations":"Fresh clone without `git fetch`; remote renamed from `origin`; target branch deleted on the remote; pushing-only remotes where tracking refs were pruned.","solutions":["Run `git fetch <fetch_remote_name>` so the remote-tracking ref exists.","Confirm the remote name and target branch: `git branch -r | grep <target_branch_name>`.","Push the target branch to the remote if it only exists locally.","Fix the project's configured target/fetch remote settings if they point at a stale remote."],"exampleFix":"// before\n// assumes origin/main exists\nland(target_branch_name = \"main\", fetch_remote_name = \"origin\");\n// after\nrepo.remote_at(\"origin\")?; // ensure remote configured\nrun(\"git\", &[\"fetch\", \"origin\", \"main\"])?; // create refs/remotes/origin/main\nland(target_branch_name = \"main\", fetch_remote_name = \"origin\");","handlingStrategy":"validation","validationCode":"// ensure the remote-tracking ref exists before deciding land outcome\nlet target = format!(\"refs/remotes/{remote}/{target_branch}\");\nif repo.try_find_reference(&target)?.is_none() {\n    run_git(&[\"fetch\", remote, target_branch])?; // or fail fast\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = decide_land(...) {\n    if e.to_string().contains(\"Target branch\") && e.to_string().contains(\"not found\") {\n        run_git(&[\"fetch\", remote])?; // then retry\n    } else { return Err(e); }\n}","preventionTips":["Always `git fetch <remote>` before merge/land operations","Verify configured remote name matches reality (`git remote -v`)","Ensure the target branch actually exists on the remote"],"tags":["git","remote","branch-not-found","merge"],"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"}