|
| 1 | +--- |
| 2 | +name: graphite-is-being-a-piece-of-shit-just-merge-my-stack |
| 3 | +description: Merge a stacked Graphite branch chain with gh by retargeting each PR to main and merging bottom to top, including conflict recovery via rebase. |
| 4 | +license: MIT |
| 5 | +compatibility: Requires GitHub CLI (gh), git, and push access. |
| 6 | +metadata: |
| 7 | + author: rivet |
| 8 | + version: "1.0" |
| 9 | +--- |
| 10 | + |
| 11 | +Merge a stacked PR chain when Graphite automation is failing. |
| 12 | + |
| 13 | +**Input**: A target branch in the stack (usually the top branch to merge through). |
| 14 | + |
| 15 | +**Goal**: Merge all PRs from the bottom of that stack up to the target branch. |
| 16 | + |
| 17 | +## Steps |
| 18 | + |
| 19 | +1. **Resolve the target PR** |
| 20 | + - Find PR for the provided branch: |
| 21 | + - `gh pr list --state open --head "<target-branch>" --json number,headRefName,baseRefName,url` |
| 22 | + - If no open PR exists, stop and report. |
| 23 | + |
| 24 | +2. **Build the stack chain down to main** |
| 25 | + - Start at target PR. |
| 26 | + - Repeatedly find the PR whose `headRefName` equals the current PR `baseRefName`. |
| 27 | + - Continue until base is `main` or no parent PR exists. |
| 28 | + - If chain is ambiguous, stop and ask the user which branch to follow. |
| 29 | + |
| 30 | +3. **Determine merge order** |
| 31 | + - Merge from **bottom to top**. |
| 32 | + - Example: `[bottom, ..., target]`. |
| 33 | + |
| 34 | +4. **For each PR in order** |
| 35 | + - Retarget to `main` before merge: |
| 36 | + - `gh pr edit <pr-number> --base main` |
| 37 | + - Merge with repository-compatible strategy: |
| 38 | + - Try `gh pr merge <pr-number> --squash --delete-branch=false` |
| 39 | + - If merge fails due conflicts: |
| 40 | + - `gh pr checkout <pr-number>` |
| 41 | + - `git fetch origin main` |
| 42 | + - `git rebase origin/main` |
| 43 | + - Resolve conflicts. If replaying already-upstream commits from lower stack layers, prefer `git rebase --skip`. |
| 44 | + - Continue with `GIT_EDITOR=true git rebase --continue` when needed. |
| 45 | + - `git push --force-with-lease origin <head-branch>` |
| 46 | + - Retry `gh pr merge ... --squash`. |
| 47 | + |
| 48 | +5. **Verify completion** |
| 49 | + - Confirm each PR in chain is merged: |
| 50 | + - `gh pr view <pr-number> --json state,mergedAt,url` |
| 51 | + - Report final ordered merge list with PR numbers and timestamps. |
| 52 | + |
| 53 | +## Guardrails |
| 54 | + |
| 55 | +- Always merge in bottom-to-top order. |
| 56 | +- Do not use merge commits if the repo disallows them. |
| 57 | +- Do not delete remote branches unless explicitly requested. |
| 58 | +- If a conflict cannot be safely resolved, stop and ask the user. |
| 59 | +- If force-push is required, use `--force-with-lease`, never `--force`. |
| 60 | +- After finishing, return to the user's original branch unless they asked otherwise. |
0 commit comments