gitbutlerapp/gitbutler · error
Cannot unapply non-existing branch
Error message
Cannot unapply non-existing branch '{branch}' What it means
Raised by unapply when the requested branch is neither the workspace reference nor found as a segment/stack in the workspace, and no branch ref exists for it either. It means there is nothing to unapply — the branch name likely was mistyped or the branch was already removed. Verify with but status that the branch is part of the workspace.
Solutions
- Verify the branch exists (`git rev-parse --verify <ref>`) before calling unapply
- Refresh workspace state and retry; if the branch is gone the unapply already happened
- Treat branch-not-found as a no-op in your caller if idempotency is desired
Example fix
// before
unapply(repo, meta, &ws, branch, ...)?;
// after
if repo.try_find_reference(&branch)?.is_some() {
unapply(repo, meta, &ws, branch, ...)?;
} Defensive patterns
Strategy: validation
Validate before calling
fn branch_exists(repo: &gix::Repository, branch: &gix::refs::FullNameRef) -> bool {
repo.try_find_reference(branch).map_or(false, |r| r.is_some())
} Try / catch
match err {
e if e.to_string().contains("non-existing branch") => return Ok(Outcome::noop()), // already gone
e => return Err(e),
} Prevention
- Refresh workspace/branch state before operating on user-selected branches
- Make unapply flows idempotent by checking ref existence first
When it happens
Trigger: Calling `unapply` with a `branch` refname that was already deleted (or never existed) and is not found by `ws.find_segment_and_stack_by_refname`, with `branch_ref.is_none()` (no git ref exists).
Common situations: Stale UI state pointing at a branch deleted in another window; typos in ref names in scripts; racing with a concurrent unapply/apply that already removed the branch.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Cannot apply non-existing branch
- failed to find branch
- Local branch ' ' not found
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/4c2850a4f6adb6bb.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/unapply.rs:238
);
}
if let Some(workspace_ref_name) = workspace_ref_name.as_ref()
&& workspace_ref_name == branch
{
return unapply_workspace_reference(
ws,
repo,
meta,
workspace_ref_name.as_ref(),
workspace_disposition,
);
}
let branch_in_ws = ws.find_segment_and_stack_by_refname(branch);
if branch_in_ws.is_none() {
if branch_ref.is_none() {
bail!(
"Cannot unapply non-existing branch '{branch}'",
branch = branch.shorten()
);
}
// The branch exists in Git, but does not in the workspace: Nothing to do.
return Ok(Outcome::new(Cow::Borrowed(workspace)));
}
let Some(workspace_ref_name) = workspace_ref_name else {
// This is an ad-hoc workspace by merit of being unnamed.
bail!("Cannot unapply a branch from an ad-hoc detached workspace");
};
let mut ws_md = meta.workspace(workspace_ref_name.as_ref())?;
if ws.kind.has_managed_ref() || ws.has_metadata() {
ws.reconcile_metadata(&mut ws_md)?;
}
let branch_removed_from_ws_meta = ws_md.unapply_branch(branch);
if !branch_removed_from_ws_meta {
// The branch wasn't in workspace metadata, yet it was present, so also delete its branch metadataView on GitHub (pinned to 58e5313667)