{"record":{"id":"60babaa03c435de1","repo":"zed-industries/zed","slug":"branch-not-found","errorCode":null,"errorMessage":"Branch '{}' not found","messagePattern":"Branch '(.+?)' not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/git/src/repository.rs","lineNumber":2346,"sourceCode":"                git.run(&args).await?;\n                anyhow::Ok(())\n            })\n            .boxed()\n    }\n\n    fn checkout_branch_in_worktree(\n        &self,\n        branch_name: String,\n        worktree_path: PathBuf,\n        create: bool,\n    ) -> BoxFuture<'_, Result<()>> {\n        let git_binary = GitBinary::new(\n            self.any_git_binary_path.clone(),\n            worktree_path,\n            self.path(),\n            self.executor.clone(),\n            self.is_trusted(),\n        );\n\n        self.executor\n            .spawn(async move {\n                if create {\n                    git_binary.run(&[\"checkout\", \"-b\", &branch_name]).await?;\n                } else {\n                    git_binary.run(&[\"checkout\", &branch_name]).await?;\n                }\n                anyhow::Ok(())\n            })\n            .boxed()\n    }\n\n    fn change_branch(&self, name: String) -> BoxFuture<'_, Result<()>> {\n        let git_binary = self.git_binary_in_worktree();\n        self.executor\n            .spawn(async move {\n                let git_binary = git_binary?;","sourceCodeStart":2328,"sourceCodeEnd":2364,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/git/src/repository.rs#L2328-L2364","documentation":"change_branch() first checks `refs/heads/<name>`, then `refs/remotes/<name>`; only if neither ref exists does it bail with this message. For remote branches the name must include the remote prefix (for example `origin/main`), in which case a tracking local branch is created and checked out.","triggerScenarios":"Calling change_branch with a name that is neither a local branch nor an existing remote-tracking ref: the tracking ref was pruned (`git fetch --prune` after upstream deleted the branch), the branch was never fetched, the remote was renamed, or a local-branch form was passed when only the qualified remote form exists.","commonSituations":"Branch pickers showing cached/stale branch lists; after the default branch was renamed upstream; shallow clones with restricted refspecs; projects whose remotes changed and old names linger in saved state.","solutions":["Refresh remote state so tracking refs match reality: `git fetch --prune`.","Use the qualified name `origin/<branch>` when the branch only exists on the remote.","Verify before calling: `git show-ref --verify refs/heads/<name>` and `git show-ref --verify refs/remotes/<remote>/<name>`.","On this error, refresh the branch list instead of retrying the same stale name."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn ref_exists(git: &GitBinary, reference: &str) -> impl Future<Output = bool> + '_ {\n    async move {\n        git.run(&[\"show-ref\", \"--verify\", \"--quiet\", reference]).await.is_ok()\n    }\n}\n\nlet target = if ref_exists(&git, &format!(\"refs/heads/{name}\")).await\n    || ref_exists(&git, &format!(\"refs/remotes/{name}\")).await\n{\n    name.clone()\n} else {\n    git.run(&[\"fetch\", \"--prune\"]).await?;\n    anyhow::ensure!(\n        ref_exists(&git, &format!(\"refs/remotes/{name}\")).await,\n        \"Branch '{name}' not found locally or on the remote\"\n    );\n    name.clone()\n};","typeGuard":null,"tryCatchPattern":"match repo.change_branch(name.clone()).await {\n    Err(e) if e.to_string().contains(\"not found\") => {\n        // refresh branch list (fetch --prune) and let the user re-pick\n    }\n    other => other?,\n}","preventionTips":["Use qualified `remote/branch` names when targeting remote branches.","Run `git fetch --prune` before presenting branch lists so pruned refs disappear.","Validate refs with `git show-ref --verify` before switching; treat stale names as refresh signals, not retry candidates."],"tags":["git","branch","checkout","refs"],"backgroundTag":"git-branch-not-found","analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}