gitbutlerapp/gitbutler · error
Unexpectedly failed to find anchor for
Error message
Unexpectedly failed to find anchor for {rn} to make it a dependent branch What it means
In the apply flow's `else` branch, the anchor reference needed to turn an incoming remote branch into a dependent branch could not be found in the workspace graph, which the code considers impossible ('Unexpectedly'). The apply aborts rather than misplacing the branch.
Solutions
- Ensure the anchor branch referenced by the workspace still exists; restore it if deleted
- Recompute/refresh the workspace and metadata, then retry apply
- File a bug with reproduction if the state appears consistent
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm the anchor branch for the incoming remote branch is applied
if !workspace_has_ref(&ws, &anchor_ref) {
return Err("anchor branch not applied; apply it first");
} Try / catch
match apply(...) {
Err(e) if e.to_string().contains("failed to find anchor") => { refresh_workspace_and_retry(); }
Err(e) => return Err(e.into()),
Ok(r) => r,
} Prevention
- Ensure anchor branches referenced by adhoc workspaces still exist
- Recompute workspace state after any manual branch deletion
- File a bug with a reproduction if the state looks consistent
When it happens
Trigger: Applying a branch into an adhoc workspace when the computed anchor reference for the dependent-branch insertion is absent from the workspace graph/metadata.
Common situations: Workspace graph computed from an older state than the metadata; anchor branch was deleted concurrently; bug in adhoc-workspace handling.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Failed to assure that
- Missing reference which should be known to workspace…
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/1d8dc0737625d3bf.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/apply.rs:702
);
}
Some(false) => {
// The branch already existed, probably as stack, but it didn't come through. Remove it and use the anchor.
ws_mut.remove_segment(rn.as_ref());
if ws_mut.insert_new_segment_above_anchor_if_not_present(
rn.as_ref(),
segment_to_insert_above,
) != Some(true)
{
bail!(
"Failed to assure that {rn} is in the workspace as dependent branch after removing it"
);
}
}
Some(true) => {}
}
} else {
bail!("Unexpectedly failed to find anchor for {rn} to make it a dependent branch")
}
}
// Redo the merge, with the different stack configuration.
// Note that this is the exception, typically using stacks will be fine.
let existing_stacks_superseded_by_branch =
find_superseded_stacks(branch.as_ref(), &ws, &mut ws_md);
merge_result = WorkspaceCommit::from_new_merge_with_metadata(
filter_superseded_metadata_stacks(
ws_md.stacks.iter(),
&existing_stacks_superseded_by_branch,
),
filter_superseded_anon_stacks(
anon_stacks(&ws.stacks),
&existing_stacks_superseded_by_branch,
),
&ws.graph,
&in_memory_repo,View on GitHub (pinned to 58e5313667)