gitbutlerapp/gitbutler · error
Failed to apply branch
Error message
Failed to apply branch: {outcome} What it means
When confirming the apply operation from the TUI stack show picker, the legacy apply command is run for the selected branch. If the apply ends with ApplyOutcome::ConflictAborted, the handler bails with a message describing the conflict outcome instead of proceeding. It signals that the branch could not be applied because applying produced conflicts that the user aborted.
Solutions
- Resolve the conflicting changes in the worktree, then retry the apply from the picker
- Inspect the reported conflict outcome, update/rebase the branch onto the current base, and retry
- Abort unrelated local changes or stash the worktree to a clean state before applying
Defensive patterns
Strategy: try-catch
Validate before calling
// best-effort pre-check: ensure the worktree has no obvious conflicts before applying
if git_status_has_unmerged_paths(&repo)? { /* warn the user */ } Try / catch
match apply::run(ctx, guard.write_permission(), op) {
Ok(ApplyOutcome::ConflictAborted(outcome)) => show_conflict_help(outcome),
Ok(_) => proceed(),
Err(e) => show_error(e),
} Prevention
- Keep the base worktree clean before applying branches
- Rebase the branch onto the current base regularly
- Read the conflict outcome message and resolve hunks before retrying
When it happens
Trigger: Selecting a branch in the stack-show apply picker whose application onto the target base produces merge conflicts and the conflict resolution was aborted (ApplyOutcome::ConflictAborted).
Common situations: Applying a branch whose changes overlap conflicting hunks with the base worktree; stale base with unmerged downstream changes; running the TUI apply action in a dirty worktree.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- Branch ' ' already exists
- Branch ' ' cannot be created: the target commit ( ) already…
- Cannot amend a conflicted commit
- Cannot rename to ' ': a branch with that name already exists
- Cannot unapply branch by checking out conflicted commit
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/63dace1935d1f7b8.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/status/tui/app/stack_mode.rs:438
b.has_local
.cmp(&a.has_local)
.then_with(|| b.updated_at.cmp(&a.updated_at))
.then_with(|| a.name.cmp(&b.name))
});
let Some(items) = NonEmpty::from_vec(branches) else {
return Ok(());
};
let picker = FuzzyPicker::new(items, self.theme, |item, ctx, messages| {
let branch = {
let repo = ctx.repo.get()?;
BranchArg(item.name.clone()).resolve_legacy_top_level_apply_branch_name(&repo)?
};
let mut guard = ctx.exclusive_worktree_access();
match apply::run(ctx, guard.write_permission(), ApplyOperation { branch })? {
ApplyOutcome::ConflictAborted(outcome) => {
anyhow::bail!("Failed to apply branch: {outcome}")
}
ApplyOutcome::AlreadyApplied { .. } | ApplyOutcome::Applied { .. } => {}
}
messages.extend([
Message::EnterNormalModeAfterConfirmingOperation,
Message::Reload(
Some(SelectAfterReload::Branch(item.name)),
ReloadCause::Mutation,
),
]);
Ok(())
});
self.modal = Some(Modal::ApplyStackPicker {
picker: Box::new(picker),
key_binds: fuzzy_picker_key_binds(),
});View on GitHub (pinned to 58e5313667)