{"record":{"id":"dc05ba3bd7c14b3f","repo":"gitbutlerapp/gitbutler","slug":"branch-no-longer-exists","errorCode":null,"errorMessage":"branch '{}' no longer exists","messagePattern":"branch '(.+?)' no longer exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":742,"sourceCode":"    ) -> Result<gix::ObjectId> {\n        if let Some(branch) = stack.heads.last() {\n            branch_head_oid(branch, repo)\n        } else {\n            Ok(default_target_oid)\n        }\n    }\n\n    pub(super) fn sync_stack_heads_from_refs(stack: &mut Stack, repo: &gix::Repository) -> bool {\n        let mut changed = false;\n        for head in &mut stack.heads {\n            changed |= sync_branch_head_from_ref(head, repo).unwrap_or(false);\n        }\n        changed\n    }\n\n    fn branch_head_oid(branch: &StackBranch, repo: &gix::Repository) -> Result<gix::ObjectId> {\n        let Some(mut reference) = repo.try_find_reference(&branch.name)? else {\n            bail!(\"branch '{}' no longer exists\", branch.name);\n        };\n        Ok(reference.peel_to_commit()?.id)\n    }\n\n    pub(super) fn set_reference_to_stored_head(\n        branch: &StackBranch,\n        repo: &gix::Repository,\n    ) -> Result<()> {\n        repo.reference(\n            qualified_reference_name(&branch.name),\n            branch.head,\n            gix::refs::transaction::PreviousValue::Any,\n            \"GitButler reference\",\n        )?;\n        Ok(())\n    }\n\n    fn sync_branch_head_from_ref(branch: &mut StackBranch, repo: &gix::Repository) -> Result<bool> {","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L724-L760","documentation":"Thrown by `branch_head_oid` when a branch recorded in a stored stack state no longer has a corresponding git reference in the repository. When reading or syncing stack heads (e.g. during oplog state restore or reference sync), each `StackBranch` name must resolve to an existing ref; if `try_find_reference` returns `None`, the branch was deleted externally.","triggerScenarios":"`restore_snapshot`/state restore calls `stack_head_oid` or `sync_branch_head_from_ref`, which calls `branch_head_oid` for a branch that was deleted via `git branch -D`, a rebase cleanup, or another tool while GitButler state still lists it.","commonSituations":"Deleting a branch with the git CLI while GitButler is open; branch deleted by a teammate and fetched state pruned it; switching machines with copied repos; force-pushes that removed remote branches backing local stack state.","solutions":["Recreate the missing branch: `git branch <branch-name> <some-commit>` so the stored head can resolve","Remove the stale branch from the GitButler workspace/stack state (e.g. `but branch delete` or unapply it in the UI)","Restore a snapshot taken before the branch was deleted","Re-apply the workspace (`but unapply` / `but apply`) so stack state is rebuilt from current refs"],"exampleFix":"// stored stack references branch 'feature-x' which was deleted\n// before: branch 'feature-x' no longer exists\n// after:\n//   git branch feature-x 9c8b7a6f5e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b","handlingStrategy":"try-catch","validationCode":"// before restoring, check all stack branches still resolve\nfor b in &stack_branches {\n    if repo.try_find_reference(&b.name)?.is_none() {\n        recreate_or_remove_branch(&b.name)?;\n    }\n}","typeGuard":null,"tryCatchPattern":"// match on the error and heal state\nmatch stack_head_oid(&stack, &repo) {\n    Err(e) if e.to_string().contains(\"no longer exists\") => {\n        recreate_branch(&stack.name)?;\n    }\n    other => other?,\n}","preventionTips":["Delete branches through GitButler (UI/CLI) rather than `git branch -D` while managed","Re-run `but status`/refresh after external git operations","Recreate accidentally deleted branches before restoring old snapshots","Avoid sharing one repository between GitButler and scripts that prune branches"],"tags":["git","branch","missing-ref","state-desync"],"backgroundTag":"entity-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"}