gitbutlerapp/gitbutler · error
Refusing to work on workspace whose workspace commit isn't…
Error message
Refusing to work on workspace whose workspace commit isn't at the top
What it means
This error is thrown by `but_workspace::branch::unapply` when the workspace's workspace commit exists in the ancestry of HEAD but is not HEAD itself. Unapply requires the workspace commit to be the tip so it can rewrite history on top of it; a stale/buried workspace commit means the workspace state is out of date.
Solutions
- Refresh the workspace first (apply/assign operation that recreates the workspace commit at HEAD), then retry unapply
- Commit or discard any in-progress changes so the workspace commit can be regenerated at the top
- If HEAD moved via plain git commands, re-run the workspace projection (`but status` / reopen the project in GitButler)
Example fix
// before
but_workspace::branch::unapply(repo, meta, &ws, branch, ...)?;
// after
if ws.has_workspace_commit_in_ancestry(repo) {
// rebuild workspace so its commit is at the tip
but_workspace::ui::rebuild_workspace(...)?;
}
but_workspace::branch::unapply(repo, meta, &ws, branch, ...)?; Defensive patterns
Strategy: validation
Validate before calling
fn workspace_commit_is_tip(ws: &Workspace, repo: &gix::Repository) -> bool {
!ws.has_workspace_commit_in_ancestry(repo)
} Prevention
- Rebuild/refresh the workspace after any external git mutation before workspace operations
- Avoid mixing plain git commands (commit/rebase/pull) with GitButler workspace operations on the same repo
When it happens
Trigger: Calling `unapply` after new commits were created on the branch without the workspace being rebuilt, or after external git operations (rebase, reset, cherry-pick) moved HEAD beyond the workspace commit.
Common situations: Running `git pull`/`git commit` directly in a GitButler-managed workspace then trying to unapply a branch from the UI/CLI; a stale workspace after a version upgrade; concurrent modification of the repo.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
- BUG: failed to apply head ref
- Cannot add the target
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/f1796c4ce4a6cffc.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/unapply.rs:205
#[tracing::instrument(skip(workspace, repo, meta), err(Debug))]
pub fn unapply<'ws>(
branch: &FullNameRef,
workspace: &'ws but_graph::Workspace,
repo: &gix::Repository,
meta: &mut impl RefMetadata,
Options {
workspace_disposition,
}: Options,
) -> anyhow::Result<Outcome<'ws>> {
let ws = workspace;
let mut branch_ref = try_find_validated_ref(repo, branch, "unapply")?;
let branch_commit_id = branch_ref
.as_mut()
.map(|reference| reference.peel_to_id().map(|id| id.detach()))
.transpose()?;
if ws.has_workspace_commit_in_ancestry(repo) {
bail!("Refusing to work on workspace whose workspace commit isn't at the top");
}
let workspace_ref_name = ws.ref_name().map(ToOwned::to_owned);
if matches!(ws.kind, but_graph::workspace::WorkspaceKind::AdHoc)
&& branch_ref
.as_ref()
.zip(workspace_ref_name.as_ref())
.is_some_and(|(to_unapply, workspace_ref_name)| {
to_unapply.name() == workspace_ref_name.as_ref()
})
{
bail!(
"Cannot unapply branch '{branch}' from an ad-hoc workspace because the workspace cannot be empty",
branch = branch.shorten()
);
}
if let Some(workspace_ref_name) = workspace_ref_name.as_ref()View on GitHub (pinned to 58e5313667)