{"record":{"id":"fd9e4b9c5a2047a2","repo":"gitbutlerapp/gitbutler","slug":"remote-tracking-branch-does-not-exist","errorCode":null,"errorMessage":"Remote-tracking branch {} does not exist","messagePattern":"Remote-tracking branch (.+?) does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/mod.rs","lineNumber":597,"sourceCode":"    }\n    let merge_key = gix::config::tree::Branch::MERGE.name;\n    if section.value(merge_key).is_none() {\n        section.push(merge_key, Some(upstream_branch.as_bstr()))?;\n    }\n    Ok((config, remote_tracking_commit_id.into()))\n}\n\n/// Return the local tracking branch of `remote_tracking_ref`, creating it at the remote-tracking\n/// commit with tracking configuration if it doesn't exist yet, like `git checkout <name>` does.\n///\n/// An existing local tracking branch is returned as is, even if it diverged from the remote.\npub fn local_tracking_branch(\n    repo: &gix::Repository,\n    remote_tracking_ref: &gix::refs::FullNameRef,\n) -> anyhow::Result<gix::refs::FullName> {\n    // Symbolic ones, `origin/HEAD` say, would make a local branch of the name they point through.\n    if try_find_validated_ref(repo, remote_tracking_ref, \"check out\")?.is_none() {\n        anyhow::bail!(\n            \"Remote-tracking branch {} does not exist\",\n            remote_tracking_ref.as_bstr()\n        );\n    }\n    let Some((local_tracking_ref, _remote)) =\n        repo.upstream_branch_and_remote_for_tracking_branch(remote_tracking_ref)?\n    else {\n        anyhow::bail!(\n            \"Couldn't find remote refspecs that would match {}\",\n            remote_tracking_ref.as_bstr()\n        );\n    };\n    if repo\n        .try_find_reference(local_tracking_ref.as_ref())?\n        .is_some()\n    {\n        return Ok(local_tracking_ref);\n    }","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/mod.rs#L579-L615","documentation":"local_tracking_branch first validates that the given remote-tracking reference actually exists in the repository (and is not symbolic). If try_find_validated_ref returns None, the ref name refers to something that isn't in the repo, so deriving a local tracking branch is impossible.","triggerScenarios":"Calling local_tracking_branch(repo, remote_tracking_ref) with a FullNameRef like refs/remotes/origin/feature that was never fetched and thus does not exist locally.","commonSituations":"Referring to a remote branch before `git fetch`; stale references to branches deleted on the remote; typos in the remote-tracking ref name.","solutions":["Fetch the remote so the tracking ref is created: `git fetch origin`","Verify the ref exists with `git rev-parse refs/remotes/origin/feature` before calling the API","Correct the ref name spelling (compare with `git branch -r`)"],"exampleFix":"// before\nlet b = local_tracking_branch(&repo, \"refs/remotes/origin/feature\".try_into()?); // fails if never fetched\n// after\nif repo.try_find_reference(\"refs/remotes/origin/feature\")?.is_some() {\n    let b = local_tracking_branch(&repo, \"refs/remotes/origin/feature\".try_into()?);\n}","handlingStrategy":"validation","validationCode":"fn tracking_ref_exists(repo: &gix::Repository, r: &gix::refs::FullNameRef) -> bool {\n    repo.try_find_reference(r).map(|o| o.is_some()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"does not exist\") => {\n        eprintln!(\"run `git fetch <remote>` to create the tracking ref\");\n        anyhow::bail!(e);\n    }\n    other => other,\n}","preventionTips":["Fetch the remote before deriving local tracking branches","Validate ref names against `git branch -r` output","Watch for upstream branch deletions that invalidate cached tracking refs"],"tags":["git","refs","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"}