gitbutlerapp/gitbutler · error
Refusing to land ` ` with --whole-stack: it is not the top…
Error message
Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — unnamed segment(s) with commits sit above it (their branch refs no longer exist), so landing `{branch}` would not land the entire stack. What it means
`validate_branch_landing` refuses a `--whole-stack` land when unnamed segments with commits sit above the branch — segments whose branch refs were deleted but which still hold commits. Since `--whole-stack` must land the entire stack, landing this branch would silently exclude those orphaned commits, so the operation is refused.
Solutions
- Recreate or restore a branch on the orphaned upper commits so it has a name, then land that top segment with `--whole-stack`.
- Inspect the workspace (`but branch list` / TUI) to find the unnamed commits and discard them if unneeded.
- Land only this branch (without `--whole-stack`) if you intend to exclude the orphaned commits — but first confirm nothing depends on them.
Example fix
// before but land base-branch --whole-stack // refused: unnamed segments with commits above // after but branch create restored-top # re-assign the orphaned commits to a named branch but land restored-top --whole-stack
Defensive patterns
Strategy: validation
Validate before calling
// ensure no orphaned (unnamed) commits exist above the branch before whole-stack landing
const ws = await api.workspaceState();
const unnamedAbove = ws.stacks.flatMap(s => s.segments)
.filter(seg => seg.position > positionOf(branch) && !seg.refName && seg.commitCount > 0);
if (unnamedAbove.length) throw new Error('Restore or discard unnamed segments above before --whole-stack land'); Type guard
function hasUnnamedSegmentsAbove(segments, branchPos) {
return segments.some(s => s.position > branchPos && (s.refName == null) && s.commitCount > 0);
} Try / catch
try {
await api.land(branch, { wholeStack: true });
} catch (e) {
if (String(e).includes('unnamed segment(s) with commits sit above')) {
await restoreOrDiscardOrphanedSegments(); // then retry
} else throw e;
} Prevention
- Avoid deleting branch refs of unlanded commits; land or explicitly discard them first.
- Periodically review the workspace for unnamed segments holding commits.
- After any manual `git branch -D`, run `but status` and resolve orphaned commits before landing.
When it happens
Trigger: Calling `branch_land` with `whole_stack: true` where `scan.has_upper` is true, `scan.upper_segments` is empty (no named top), but the graph shows unnamed segments with commits above the branch — typically after branch refs above were deleted without their commits being landed.
Common situations: Deleting an upper branch in the GitButler UI/CLI (or manually with `git branch -D`) and later trying to whole-stack-land a lower branch; workspace cleanup that removed refs while commits remained; stale stacks left from interrupted operations.
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
- Refusing to land ` `: commit(s) on unnamed segment(s) below…
- Cannot land ` `: it would publish conflicted commit ( )…
- Refusing to land ` `: it is stacked on top of other…
- Refusing to land ` ` with --whole-stack: it is not the top…
- Aborting due to empty branch name
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/585436befe566679.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-api/src/land/mod.rs:416
ctx: &mut Context,
branch: &str,
target_display: &str,
whole_stack: bool,
) -> anyhow::Result<Vec<String>> {
let Some(scan) = scan_stack(ctx, branch)? else {
return Ok(Vec::new());
};
if whole_stack && scan.has_upper {
// Judge "top of the stack" by position, not by names: a segment whose branch ref was
// deleted still holds commits that "land the entire stack" would have to include.
if let Some(top) = scan.upper_segments.first() {
bail!(
"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack. \
--whole-stack lands the entire stack; name its top segment `{top}` instead.",
);
}
bail!(
"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — \
unnamed segment(s) with commits sit above it (their branch refs no longer exist), so \
landing `{branch}` would not land the entire stack.",
);
}
// Key off the commits below, not the segment names: segments whose branch ref was deleted are
// unnamed but their commits would be published all the same.
let publishes_below = scan.commits_below > 0 || !scan.lower_segments.is_empty();
if publishes_below && !whole_stack {
if scan.lower_segments.is_empty() {
bail!(
"Refusing to land `{branch}`: {} commit(s) on unnamed segment(s) below it would \
also be published to {target_display}. Pass --whole-stack to land `{branch}` \
together with everything below it.",
scan.commits_below,
);
}
bail!(View on GitHub (pinned to 58e5313667)