gitbutlerapp/gitbutler · error

Refusing to land ` `: it is stacked on top of other…

Error message

Refusing to land `{branch}`: it is stacked on top of {} other segment(s) ({}) whose commits would also be published to {target_display}. Land the bottom segment `{}`, or pass --whole-stack to land `{branch}` together with everything below it.

What it means

`validate_branch_landing` refuses to land a branch that is stacked on top of named lower segments when `--whole-stack` is not passed. Landing this branch would push the lower segments' commits to the target as well, so GitButler refuses and suggests either landing the bottom segment first or passing `--whole-stack` to publish the whole stack.

Solutions

  1. Land the bottom segment first: `but land <bottom-segment>` (named in the error message).
  2. Pass `--whole-stack` to land everything below together: `but land <branch> --whole-stack`.
  3. Rebase the branch so it no longer depends on unpublished lower segments if independent landing is intended.

Example fix

// before
but land feature-2   // refused: stacked on 1 other segment (feature-1)
// after
but land feature-1   # land bottom first, then
but land feature-2
Defensive patterns

Strategy: validation

Validate before calling

// land bottom-up: only land a branch when no named segments remain below it
const stack = await api.listStacks();
const s = stack.find(s => s.branches.includes(branch));
const below = s.branches.slice(0, s.branches.indexOf(branch));
if (below.length && !opts.wholeStack) throw new Error(`Land ${below[0]} first, or use --whole-stack`);

Type guard

null

Try / catch

try {
  await api.land(branch);
} catch (e) {
  const m = String(e).match(/Land the bottom segment `([^`]+)`/);
  if (m) await api.land(m[1]); // land bottom-up, then retry
  else throw e;
}

Prevention

When it happens

Trigger: Calling `branch_land` without `whole_stack` where `scan.lower_segments` is non-empty — e.g. `but land feature-2` when the stack is `feature-1 -> feature-2` and both would be published to the target.

Common situations: Standard stacked-PR workflow where a developer tries to land an upper branch before the lower ones; forgetting GitButler publishes the full ancestry to the target; automation that lands a fixed branch name regardless of stack position.

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


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

Appendix: source

Thrown at crates/but-api/src/land/mod.rs:434

        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!(
            "Refusing to land `{branch}`: it is stacked on top of {} other segment(s) ({}) \
             whose commits would also be published to {target_display}. Land the bottom segment \
             `{}`, or pass --whole-stack to land `{branch}` together with everything below it.",
            scan.lower_segments.len(),
            scan.lower_segments.join(", "),
            scan.lower_segments.last().expect("non-empty checked above"),
        );
    }

    if !scan.conflicted.is_empty() {
        bail!(
            "Cannot land `{branch}`: it would publish {} conflicted commit{} ({}). \
             Resolve them first with `but resolve <commit>`.",
            scan.conflicted.len(),
            if scan.conflicted.len() == 1 { "" } else { "s" },
            scan.conflicted.join(", "),
        );
    }

View on GitHub (pinned to 58e5313667)