{"record":{"id":"7e91aba80aab02c5","repo":"gitbutlerapp/gitbutler","slug":"refusing-to-land-branch-it-is-stacked-on-top","errorCode":null,"errorMessage":"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.","messagePattern":"Refusing to land `(.+?)`: it is stacked on top of (.+?) other segment\\(s\\) \\((.+?)\\) whose commits would also be published to (.+?)\\. Land the bottom segment `(.+?)`, or pass --whole-stack to land `(.+?)` together with everything below it\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/land/mod.rs","lineNumber":434,"sourceCode":"        bail!(\n            \"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — \\\n             unnamed segment(s) with commits sit above it (their branch refs no longer exist), so \\\n             landing `{branch}` would not land the entire stack.\",\n        );\n    }\n    // Key off the commits below, not the segment names: segments whose branch ref was deleted are\n    // unnamed but their commits would be published all the same.\n    let publishes_below = scan.commits_below > 0 || !scan.lower_segments.is_empty();\n    if publishes_below && !whole_stack {\n        if scan.lower_segments.is_empty() {\n            bail!(\n                \"Refusing to land `{branch}`: {} commit(s) on unnamed segment(s) below it would \\\n                 also be published to {target_display}. Pass --whole-stack to land `{branch}` \\\n                 together with everything below it.\",\n                scan.commits_below,\n            );\n        }\n        bail!(\n            \"Refusing to land `{branch}`: it is stacked on top of {} other segment(s) ({}) \\\n             whose commits would also be published to {target_display}. Land the bottom segment \\\n             `{}`, or pass --whole-stack to land `{branch}` together with everything below it.\",\n            scan.lower_segments.len(),\n            scan.lower_segments.join(\", \"),\n            scan.lower_segments.last().expect(\"non-empty checked above\"),\n        );\n    }\n\n    if !scan.conflicted.is_empty() {\n        bail!(\n            \"Cannot land `{branch}`: it would publish {} conflicted commit{} ({}). \\\n             Resolve them first with `but resolve <commit>`.\",\n            scan.conflicted.len(),\n            if scan.conflicted.len() == 1 { \"\" } else { \"s\" },\n            scan.conflicted.join(\", \"),\n        );\n    }","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/land/mod.rs#L416-L452","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Land the bottom segment first: `but land <bottom-segment>` (named in the error message).","Pass `--whole-stack` to land everything below together: `but land <branch> --whole-stack`.","Rebase the branch so it no longer depends on unpublished lower segments if independent landing is intended."],"exampleFix":"// before\nbut land feature-2   // refused: stacked on 1 other segment (feature-1)\n// after\nbut land feature-1   # land bottom first, then\nbut land feature-2","handlingStrategy":"validation","validationCode":"// land bottom-up: only land a branch when no named segments remain below it\nconst stack = await api.listStacks();\nconst s = stack.find(s => s.branches.includes(branch));\nconst below = s.branches.slice(0, s.branches.indexOf(branch));\nif (below.length && !opts.wholeStack) throw new Error(`Land ${below[0]} first, or use --whole-stack`);","typeGuard":"null","tryCatchPattern":"try {\n  await api.land(branch);\n} catch (e) {\n  const m = String(e).match(/Land the bottom segment `([^`]+)`/);\n  if (m) await api.land(m[1]); // land bottom-up, then retry\n  else throw e;\n}","preventionTips":["Adopt a bottom-up landing order for stacked branches.","Use --whole-stack deliberately when you intend to publish the whole stack at once.","Keep automation stack-aware: resolve stack position before issuing lands."],"tags":["git","stacked-branches","validation","cli"],"backgroundTag":"invalid-state-transition","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}