gitbutlerapp/gitbutler · error

Failed to unapply branch due to conflicts while rebuilding…

Error message

Failed to unapply branch due to conflicts while rebuilding the workspace merge commit: {}

What it means

Thrown by `ensure_workspace_merge_has_no_conflicts` in crates/but-workspace/src/branch/unapply.rs:543 after `gitbutler` recomputes the workspace merge commit while un-applying a branch. When the synthetic merge produces conflicts across stacks, the unapply is aborted rather than leaving the workspace in a conflicted state. The message includes a description of the conflicting stacks.

Solutions

  1. Read the conflicting stacks from the error message and manually resolve the conflicts before retrying the unapply
  2. Merge/rebase the conflicting branch into its peer branch first, then unapply
  3. Update the workspace/integration branch (fetch and rebase) so the rebuilt merge applies cleanly
  4. As a last resort, commit or stash the affected changes, unapply, and re-apply the branch

Example fix

// before
workspace.unapply_branch(branch_ref); // aborts with conflicts
// after
// resolve conflicting hunks between the two branches first
workspace.merge_branch_into_peer(conflicting_branch)?;
workspace.unapply_branch(branch_ref)?;
Defensive patterns

Strategy: try-catch

Validate before calling

// preview merge conflicts before unapplying
let outcome = workspace.simulate_unapply(branch_ref)?;
if outcome.has_conflicts() {
    eprintln!("resolve first: {:?}", outcome.conflicting_stacks);
    return;
}

Try / catch

match workspace.unapply_branch(branch_ref) {
    Err(e) if e.to_string().contains("conflicts while rebuilding") => resolve_conflicts_and_retry(),
    other => other?,
}

Prevention

When it happens

Trigger: Calling the unapply-branch API (workspace_branch_and_ancestors flow) when the branch being removed from the workspace cannot be merged out cleanly, i.e. the rebuilt workspace merge commit would have conflicts between remaining stacks or the unapplied branch's changes.

Common situations: Overlapping edits between two applied branches; the unapplied branch contains changes that were also made on the integration branch; diverged stacks with conflicting hunks in the same files; stale workspace state after upstream changes.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/e4fd181e042be1e3. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/branch/unapply.rs:543

    ) -> anyhow::Result<WorkspaceMergeAfterUnapply> {
        let mut tips = future_workspace_tips.to_vec();
        let report_workspace_merge = !tips.is_empty();
        if tips.is_empty() {
            tips.push(base_tip_after_unapply(ws, future_workspace_tips)?);
        }
        let outcome = WorkspaceCommit::from_new_merge_with_tips(tips, &ws.graph, repo, None)?;
        ensure_workspace_merge_has_no_conflicts(&outcome)?;
        let workspace_commit_id = outcome.workspace_commit_id;
        Ok(WorkspaceMergeAfterUnapply {
            workspace_commit_id,
            workspace_merge: report_workspace_merge.then_some(outcome),
        })
    }

    fn ensure_workspace_merge_has_no_conflicts(
        outcome: &crate::commit::merge::Outcome,
    ) -> anyhow::Result<()> {
        ensure!(
            !outcome.has_conflicts(),
            "Failed to unapply branch due to conflicts while rebuilding the workspace merge commit: {}",
            describe_conflicting_stacks(&outcome.conflicting_stacks)
        );
        Ok(())
    }

    fn describe_conflicting_stacks(
        conflicting_stacks: &[crate::commit::merge::ConflictingStack],
    ) -> String {
        let ref_names = conflicting_stacks
            .iter()
            .filter_map(|stack| stack.ref_name.as_ref())
            .map(|ref_name| ref_name.shorten().to_string())
            .collect::<Vec<_>>();
        if ref_names.is_empty() {
            format!("{} stack(s)", conflicting_stacks.len())
        } else {

View on GitHub (pinned to 58e5313667)