gitbutlerapp/gitbutler · error
Could not find associated reference name
Error message
Could not find associated reference name
What it means
In `but-action`'s handle_changes flow, the code looks up the stack whose id matches `stack_id` in the workspace's stack list in order to derive its branch name (which becomes `refs/heads/<name>` for committing). If no stack in the workspace has that id, this anyhow error is thrown. It is a lookup failure: the caller supplied a stack id (or the workspace state contains a stack id) that does not resolve to an existing stack entry.
Solutions
- Refresh the workspace stack list and re-resolve the stack id before calling the action.
- Verify the stack is currently applied/in the workspace (not unapplied or deleted) using `but` workspace status.
- Pass the correct stack id — pick it from the current workspace output rather than a cached value.
- If the id comes from an event/callback, re-validate it against the live workspace before use.
Example fix
// before
let stack_id = cached_stack_id;
handle_changes(..., stack_id, ...);
// after
let stacks = workspace.stacks(); // re-read current state
let stack_id = stacks.iter().find(|s| s.branch_name == "my-branch").map(|s| s.id)
.ok_or_else(|| anyhow::anyhow!("branch my-branch is not applied in the workspace"))?;
handle_changes(..., stack_id, ...); Defensive patterns
Strategy: validation
Validate before calling
// Rust: verify the stack id resolves in the current workspace before calling
let stack = workspace.stacks.iter().find(|s| s.id == stack_id)
.ok_or_else(|| anyhow::anyhow!("stack {stack_id:?} is not in the current workspace"))?; Type guard
fn stack_exists(stacks: &[Stack], id: StackId) -> bool { stacks.iter().any(|s| s.id == Some(id)) } Try / catch
match handle_changes(...) {
Err(e) if e.to_string().contains("Could not find associated reference name") => {
refresh_workspace()?; // stale id — retry once with fresh state
}
other => other?,
} Prevention
- Always resolve stack ids from a freshly read workspace, never from cached state
- Re-validate ids received from UI events against live workspace state
- Check stack applied-status before mutating operations
When it happens
Trigger: Calling the handle_changes action with a `stack_id` that is absent from `stacks` (e.g. a stale StackId captured before the stack was unapplied, deleted, or after the workspace was rebuilt); internal callers passing an id from outdated workspace metadata.
Common situations: UI or script cached a stack id from a previous operation; the stack was unapplied/removed between listing and committing; operating on a different workspace snapshot than the one the id came from.
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
- BranchNotFound
- Stack has no ID
- a committed transaction always materializes a workspace
- Ad-hoc (single-branch) branch moves are not supported…
- another pre-commit hook is already using the repository…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/03304469b0212602.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-action/src/simple.rs:113
} else {
change_summary.to_string()
};
for (stack_id, diff_specs) in stack_assignments {
if diff_specs.is_empty() {
continue;
}
if let Some(exclusive_stack) = exclusive_stack
&& exclusive_stack != stack_id
{
continue; // Skip stacks that are not the exclusive stack.
}
let stack_branch_name = stacks
.iter()
.find(|s| s.id == stack_id)
.map(|s| s.branch_name.clone())
.ok_or(anyhow!("Could not find associated reference name"))?;
let full_ref_name: gix::refs::FullName =
format!("refs/heads/{stack_branch_name}").try_into()?;
let editor = Editor::create(ws, meta, repo, db)?;
let outcome = but_workspace::commit::commit_create(
editor,
diff_specs,
RelativeToRef::Reference(full_ref_name.as_ref()),
InsertSide::Below,
&commit_message,
context_lines,
but_workspace::commit::ChangeSource::Head,
)?;
if !outcome.rejected_specs.is_empty() {
tracing::warn!(
?outcome.rejected_specs,
"Failed to commit at least one hunk"View on GitHub (pinned to 58e5313667)