{"record":{"id":"e38807d4a356a848","repo":"gitbutlerapp/gitbutler","slug":"could-not-delete-branch","errorCode":null,"errorMessage":"Could not delete branch '{}'","messagePattern":"Could not delete branch '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/branch.rs","lineNumber":1402,"sourceCode":"                )\n                .with_context(|| {\n                    format!(\n                        \"Could not create recovery ref before renaming '{}'\",\n                        ref_name.as_bstr()\n                    )\n                })?,\n            );\n\n            if let Err(delete_err) = old_reference.delete() {\n                if let Some(backup) = backup_reference.take()\n                    && let Err(err) = backup.delete()\n                {\n                    warn!(\n                        ?err,\n                        \"failed to remove branch-rename recovery ref after source deletion failed\"\n                    );\n                }\n                return Err(anyhow::Error::new(delete_err)\n                    .context(format!(\"Could not delete branch '{}'\", ref_name.as_bstr())));\n            }\n            if let Err(create_err) = repo.reference(\n                new_ref.as_ref(),\n                target_id,\n                PreviousValue::MustNotExist,\n                \"rename branch\",\n            ) {\n                let create_err = anyhow::Error::new(create_err)\n                    .context(format!(\"Could not create branch '{}'\", new_ref.as_bstr()));\n                match repo.reference(\n                    ref_name.as_ref(),\n                    target_id,\n                    PreviousValue::MustNotExist,\n                    \"restore branch after failed rename\",\n                ) {\n                    Ok(_) => {\n                        if let Some(backup) = backup_reference.take()","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/branch.rs#L1384-L1420","documentation":"Raised during a branch rename in but-api: deleting the old source reference failed, and the operation aborts with this context-wrapped error including the old branch name. A prior warning logs the failure to remove the branch-rename recovery ref after the source deletion failed.","triggerScenarios":"Calling the branch rename API when the git reference deletion for the old ref_name fails — e.g. the ref is checked out in a worktree, packed-refs is not writable, or the ref vanished concurrently.","commonSituations":"Filesystem permission problems in .git/refs, a locked repository (another GitButler/git process holds it), read-only mounts, or packed-refs/ref corruption on Windows with antivirus interference.","solutions":["Close other Git processes/GitButler instances holding the repo and retry the rename","Check filesystem permissions on .git/refs and .git/packed-refs","Verify no worktree has the branch checked out before renaming","Run git fsck / inspect packed-refs if refs appear corrupted"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { api.renameBranch(old, new); } catch (e) { if (String(e).includes('Could not delete branch')) { console.error('old ref deletion failed; close other git processes and retry'); } throw e; }","preventionTips":["Ensure the branch is not checked out in any worktree before renaming","Avoid running concurrent git operations against the same repo","Monitor .git directory permissions after OS updates"],"tags":["git","branch-rename","ref-deletion","filesystem"],"backgroundTag":"git-command-failed","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"}