gitbutlerapp/gitbutler · error
Could not delete branch
Error message
Could not delete branch '{}' What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- Cannot discard lines in
- Could not create branch
- ' ' already exists
- The repository at has no .git directory. GitButler requires…
- Aborting due to empty branch name
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e38807d4a356a848.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-api/src/branch.rs:1402
)
.with_context(|| {
format!(
"Could not create recovery ref before renaming '{}'",
ref_name.as_bstr()
)
})?,
);
if let Err(delete_err) = old_reference.delete() {
if let Some(backup) = backup_reference.take()
&& let Err(err) = backup.delete()
{
warn!(
?err,
"failed to remove branch-rename recovery ref after source deletion failed"
);
}
return Err(anyhow::Error::new(delete_err)
.context(format!("Could not delete branch '{}'", ref_name.as_bstr())));
}
if let Err(create_err) = repo.reference(
new_ref.as_ref(),
target_id,
PreviousValue::MustNotExist,
"rename branch",
) {
let create_err = anyhow::Error::new(create_err)
.context(format!("Could not create branch '{}'", new_ref.as_bstr()));
match repo.reference(
ref_name.as_ref(),
target_id,
PreviousValue::MustNotExist,
"restore branch after failed rename",
) {
Ok(_) => {
if let Some(backup) = backup_reference.take()View on GitHub (pinned to 58e5313667)