$npx -y skills add vercel/next.js --skill backport-prBackport a merged Next.js pull request from canary to a previous release branch such as next-16-2. Use when the user asks to backport, cherry-pick, or open a backport PR from a PR number to an older Next.js version. Covers finding the merged PR commit, creating a backport branch
| 1 | # Backport PR |
| 2 | |
| 3 | Use this skill when a user asks to backport a merged Next.js PR to a release |
| 4 | branch. |
| 5 | |
| 6 | ## Inputs |
| 7 | |
| 8 | - Require a PR number and a target release branch, for example `next-16-2`. |
| 9 | - If the target branch is not provided and cannot be inferred confidently from |
| 10 | the user's request, ask before mutating git state. |
| 11 | - Treat the target branch as variable; do not hard-code `next-16-2` except when |
| 12 | the user explicitly asks for it. |
| 13 | |
| 14 | ## Workflow |
| 15 | |
| 16 | 1. Inspect the current worktree before changing branches: |
| 17 | |
| 18 | ```bash |
| 19 | git status --short |
| 20 | git branch --show-current |
| 21 | ``` |
| 22 | |
| 23 | Preserve unrelated user changes. Do not overwrite, reset, or stash them |
| 24 | without the user's consent. |
| 25 | |
| 26 | 2. Sync the source and target branches: |
| 27 | |
| 28 | ```bash |
| 29 | git fetch origin canary:refs/remotes/origin/canary <target-branch>:refs/remotes/origin/<target-branch> |
| 30 | ``` |
| 31 | |
| 32 | 3. Identify the commit that landed the PR on `canary`: |
| 33 | |
| 34 | ```bash |
| 35 | gh pr view <pr-number> --repo vercel/next.js --json number,title,state,url,mergeCommit,baseRefName,headRefName |
| 36 | git log origin/canary --oneline --fixed-strings --grep="(#<pr-number>)" |
| 37 | ``` |
| 38 | |
| 39 | Prefer `mergeCommit.oid` when the PR is `MERGED` and the commit is contained |
| 40 | in `origin/canary`. If GitHub does not return a usable merge commit, use the |
| 41 | `git log --grep` result and verify the commit subject references the PR |
| 42 | number. |
| 43 | |
| 44 | 4. Create the backport branch from the release branch: |
| 45 | |
| 46 | ```bash |
| 47 | git switch -c backport-<pr-number>-to-<target-branch> origin/<target-branch> |
| 48 | ``` |
| 49 | |
| 50 | After switching branches in this repo, run `pnpm build-all` before Next.js |
| 51 | integration tests unless the user explicitly limits the task to preparing the |
| 52 | cherry-pick or PR. |
| 53 | |
| 54 | 5. Cherry-pick the landed commit with provenance: |
| 55 | |
| 56 | ```bash |
| 57 | git cherry-pick -x <merged-commit-sha> |
| 58 | ``` |
| 59 | |
| 60 | Resolve conflicts in favor of preserving the release branch's compatibility |
| 61 | constraints. If the cherry-pick is empty, verify whether the change is already |
| 62 | present on the release branch and report that instead of opening a duplicate |
| 63 | PR. |
| 64 | |
| 65 | 6. Verify with the narrowest commands that cover the touched files. Prefer |
| 66 | focused tests, `pnpm types` for TypeScript-only risk, and the relevant |
| 67 | integration test mode for behavior changes. |
| 68 | |
| 69 | 7. Open the backport PR using `$create-pr`. |
| 70 | |
| 71 | Override the normal `$create-pr` base branch: use `--base <target-branch>`, |
| 72 | not `canary`. Keep the PR as a draft unless the user explicitly asks |
| 73 | otherwise. |
| 74 | |
| 75 | ## PR Shape |
| 76 | |
| 77 | Use a title like: |
| 78 | |
| 79 | ```text |
| 80 | [backport] <original PR title> |
| 81 | ``` |
| 82 | |
| 83 | Use a concise PR body: |
| 84 | |
| 85 | ```markdown |
| 86 | Backports <original PR title/link> to `<target-branch>`. |
| 87 | |
| 88 | <!-- NEXT_JS_LLM --> |
| 89 | ``` |
| 90 | |
| 91 | ## Related Skills |
| 92 | |
| 93 | - `$create-pr` - Create the branch commit, push it, and open the draft PR. |
| 94 | - `$pr-status-triage` - Check CI failures or review feedback after the PR exists. |