{"record":{"id":"a84d72c68beee001","repo":"gitbutlerapp/gitbutler","slug":"remote-branch-target-branch-ref-not-found","errorCode":null,"errorMessage":"remote branch '{target_branch_ref}' not found","messagePattern":"remote branch '(.+?)' not found","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/gitbutler-branch-actions/src/base.rs","lineNumber":184,"sourceCode":"            .as_ref()\n            .is_some_and(|target_ref| target_ref.to_string() == target_branch_ref.to_string());\n        (\n            workspace_ref_exists && project_meta.target_commit_id.is_some() && target_ref_matches,\n            project_meta.target_ref,\n        )\n    } else {\n        (false, None)\n    };\n\n    // if target exists, and it is the same as the requested branch, we should go back\n    if existing_target_ref_matches {\n        return go_back_to_integration(ctx, perm);\n    }\n\n    // lookup a branch by name\n    let mut target_branch = repo\n        .try_find_reference(target_branch_ref.to_string().as_str())?\n        .ok_or(anyhow!(\"remote branch '{target_branch_ref}' not found\"))?;\n\n    let target_branch_head = target_branch\n        .peel_to_commit()\n        .context(format!(\n            \"failed to peel branch {target_branch_ref} to commit\"\n        ))?\n        .id;\n\n    let mut current_head = repo.head().context(\"Failed to get HEAD reference\")?;\n    let current_head_commit = current_head\n        .peel_to_commit()\n        .context(\"Failed to peel HEAD reference to commit\")?\n        .id;\n\n    // calculate the commit as the merge-base between HEAD in ctx and this target commit\n    let target_commit_oid = repo\n        .merge_base(current_head_commit, target_branch_head)\n        .map(|id| id.detach())","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/gitbutler-branch-actions/src/base.rs#L166-L202","documentation":"Changing the target/base branch looks up the remote-tracking reference by name via repo.try_find_reference. If no such reference exists locally (refs/remotes/<remote>/<branch> is absent), the lookup returns None and the target change is rejected with this error.","triggerScenarios":"Setting the target to a remote branch that was never fetched (fresh clone, shallow state), a typo in the remote/branch name, or the branch was deleted upstream and the tracking ref pruned away.","commonSituations":"Forgetting `git fetch` before setting the target; using the wrong remote name ('github/main' vs 'origin/main'); branch renamed or deleted on the remote.","solutions":["Fetch first: `git fetch --all --prune`, then retry the target command","Verify the exact remote-tracking ref exists: `git branch -r` (or `git ls-remote origin`)","Use the fully qualified remote and branch, e.g. `but config target origin/main`"],"exampleFix":"# before\nbut config target orgin/main   # typo / never fetched\n# after\ngit fetch --prune\nbut config target origin/main","handlingStrategy":"validation","validationCode":"let exists = repo\n    .rev_parse_single(format!(\"refs/remotes/{remote}/{branch}\"))\n    .is_ok();\nanyhow::ensure!(exists, \"remote branch not fetched yet; run git fetch first\");","typeGuard":null,"tryCatchPattern":"Catch this error, run `git fetch --all --prune`, and retry the target-branch operation once.","preventionTips":["Run git fetch --prune before changing the target branch","Confirm the exact remote-tracking name with `git branch -r` first"],"tags":["target-branch","remote-ref","not-found","git"],"backgroundTag":"remote-branch-not-found","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}