Merge, restack, and monitor stacked GitLab merge requests, where each MR targets the branch of the one below it. Use when an MR targets a branch other than the default branch, when a parent MR in a stack merged and the next one needs retargeting or rebasing, when a parent got new commits that the MRs above it need, or when asked to merge or watch a stack. For a single MR, use gitlab:merge-request.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Stack?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/bendrucker-stack-claude)
---
name: gitlab:stack
description: Merge, restack, and monitor stacked GitLab merge requests, where each MR targets the branch of the one below it. Use when an MR targets a branch other than the default branch, when a parent MR in a stack merged and the next one needs retargeting or rebasing, when a parent got new commits that the MRs above it need, or when asked to merge or watch a stack. For a single MR, use gitlab:merge-request.
argument-hint: "[status | restack | land] [<iid> | <branch>] [--squash]"
allowed-tools:
- Monitor
- TaskStop
- Bash(bun ${CLAUDE_SKILL_DIR}/scripts/stack.ts:*)
- Bash(glab mr:*)
- Bash(glab api:*)
---
# Stacked Merge Requests
`glab` has no stack merge. `glab stack sync` drops merged layers from its local stack but never retargets or merges an MR. `stack.ts` does both. It takes any layer's iid or branch, defaulting to the current branch, and walks the MRs down through each target branch and up through each MR that targets a layer's branch, following every child when a layer has several. A merged parent's iid also finds the children GitLab retargeted to the trunk when it deleted the parent's branch, so pass it after a parent merges. It prints one JSON object per line.
```bash
bun ${CLAUDE_SKILL_DIR}/scripts/stack.ts status [<ref>]
bun ${CLAUDE_SKILL_DIR}/scripts/stack.ts restack [<ref>]
bun ${CLAUDE_SKILL_DIR}/scripts/stack.ts land [<top>] [--squash] [--interval <seconds>]
```
## Arguments
`$0` picks the subcommand, `status` by default. `$1` is the layer. `--squash` passes to `land`, which otherwise uses the project's squash setting.
## Status
One line per layer, bottom first: `iid`, `branch`, `target`, `state`, `draft`, `status` (`detailed_merge_status`), `pipeline`, `auto_merge`, `on_target`, which is whether the layer's branch contains its target, and `merged_parent`, the iid of a merged MR whose commits the layer still carries. A layer with `merged_parent` needs `restack` before anything else is pushed to it. Merged layers below the open ones still appear while GitLab keeps their branches.
## Restack
`restack` points each open layer at the nearest open layer below it, or the trunk, and rebases it when the layer below changed under it:
- When a parent merged, by squash or not, it rebases the child onto the trunk, dropping the parent's commits, and retargets it.
- When a parent got new commits, it rebases the child onto the parent's new head.
- It leaves a layer that is only behind the trunk alone. A moving trunk never restarts CI or resets approvals.
The fork point is the newest of the parent's MR version heads that the child contains. The rebase then replays only the child's own commits, even after the parent was force-pushed. Run `restack` instead of picking SHAs for `git rebase --onto` by hand, and instead of `glab mr rebase`, which replays a squash-merged parent's commits and conflicts.
It replays commits with `git merge-tree` and needs no checkout or worktree, then pushes with `--force-with-lease`. A local branch ahead of `origin` is replayed from its local head, carrying its unpushed commits. A local branch that matched or was ahead of `origin` moves to the new head, and a worktree holding the branch must be clean. It then deletes each merged parent branch that no open MR targets. Rerunning is safe: a layer that already contains its base is skipped.
A `conflict` event leaves the branch untouched and names `onto`, `upstream`, and the `worktree` holding the branch, if any. Check the branch out there, run `git rebase --onto <onto> <upstream>`, resolve it with `git:conflicts`, push with `--force-with-lease`, then rerun `restack` for the layers above.
Retargeting resets approvals, and a push resets them when the project has `reset_approvals_on_push`. After it rebases or retargets a layer, it re-requests that layer's reviewers with a `/request_review` note and logs `rerequested`, with `error` set when the note failed.
## Land
`land` merges every layer up to and including `<top>`, bottom first. Run it with the `Monitor` tool and `persistent: true`, and report each event once. Each pass rereads the stack, restacks, and arms auto-merge on the bottom layer only, through the same path as `merge.ts --auto-merge`, which joins a merge train when the project has one. It never arms a higher layer, because GitLab would merge that layer into its parent's branch instead of the trunk.
| Event | Meaning | Exits |
| --- | --- | --- |
| `waiting` | The bottom layer's merge status, pipeline, and arming changed. `arm_error` holds a refused arm. | no |
| `rebased`, `retargeted`, `rerequested`, `deleted` | `restack` changed a layer. | no |
| `conflict` | A rebase stopped. Resolve it per [Restack](#restack), then run `land` again. | 1 |
| `failing` | The bottom layer's pipeline failed on its head. Diagnose with `gitlab:ci-monitor`. | 1 |
| `closed` | A layer at or below `<top>` was closed. | 1 |
| `done` | Every layer up to `<top>` merged. | 0 |
A `waiting` line with `not_approved` or unresolved discussions needs a person. Report it and keep the monitor running. Stop it with `TaskStop`.
## Building a Stack
Open each layer with `glab mr create --source-branch <branch> --target-branch <parent>`. Mark a layer that must not merge before another with an MR dependency per `gitlab:merge-request` (`block`).