{"record":{"id":"78ac437eb11830a0","repo":"gitbutlerapp/gitbutler","slug":"failed-to-find-branch-target-branch-refname","errorCode":null,"errorMessage":"failed to find branch {target_branch_refname}","messagePattern":"failed to find branch (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-git/src/context.rs","lineNumber":106,"sourceCode":"            force_push_protection,\n            refspec,\n            askpass_broker,\n            push_opts,\n        )\n    }\n\n    fn git_test_push(\n        &self,\n        remote_name: &str,\n        branch_name: &str,\n        askpass: Option<Option<StackId>>,\n    ) -> Result<()> {\n        let target_branch_refname: gix::refs::FullName =\n            format!(\"refs/remotes/{remote_name}/{branch_name}\").try_into()?;\n        let repo = self.repo.get()?;\n        let mut branch = repo\n            .try_find_reference(&target_branch_refname.to_string())?\n            .ok_or(anyhow!(\"failed to find branch {target_branch_refname}\"))?;\n\n        let commit_id = branch.peel_to_commit()?.id;\n        let branch_name = format!(\"test-push-{}\", now_ms());\n        let refname: gix::refs::FullName =\n            format!(\"refs/remotes/{remote_name}/{branch_name}\").try_into()?;\n\n        self.push(\n            commit_id,\n            refname.clone(),\n            false,\n            false,\n            None,\n            askpass,\n            vec![],\n        )\n        .map_err(|err| anyhow!(err.to_string()))?;\n\n        let empty_refspec = Some(format!(\":refs/heads/{branch_name}\"));","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-git/src/context.rs#L88-L124","documentation":"Thrown in git_test_push when the remote-tracking ref `refs/remotes/<remote>/<branch>` cannot be found in the repository. The code looks up the ref to obtain its commit for the test push; a missing ref means the remote branch does not exist locally as a tracking ref.","triggerScenarios":"Calling git_test_push for a remote/branch pair where `refs/remotes/<remote_name>/<branch_name>` does not exist locally — the remote branch was never fetched, was deleted upstream, or remote/branch names are misspelled.","commonSituations":"Testing a push to a branch that was force-deleted on the remote; shallow or fresh clone without `git fetch`; typo in remote_name or branch_name; remote-tracking refs pruned.","solutions":["Run `git fetch <remote_name>` to populate the remote-tracking ref first.","Verify remote_name and branch_name are correct (`git branch -r`).","If the remote branch was deleted upstream, prune stale refs (`git fetch --prune`) and choose an existing branch.","Ensure the ref exists before calling: try_find_reference and handle None."],"exampleFix":"// before\nctx.git_test_push(\"origin\", \"feature\")?; // ref missing\n// after\nctx.fetch(\"origin\", None)?;\nctx.git_test_push(\"origin\", \"feature\")?;","handlingStrategy":"validation","validationCode":"let tracking = format!(\"refs/remotes/{remote}/{branch}\");\nif repo.try_find_reference(&tracking)?.is_none() {\n    // fetch first or surface a clear message\n    ctx.fetch(remote, None)?;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch the remote before any push-test logic that reads tracking refs.","Verify branch exists on remote with `git ls-remote <remote> <branch>`.","Use git fetch --prune to keep tracking refs truthful."],"tags":["git","branch","not-found"],"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"}