Stacked PRs are now live on GitHub

Stacked PRs are now live on GitHub

GitHub 现已支持 Stacked PRs(堆叠式拉取请求)

Stacked pull requests break large changes into small, reviewable pull requests. They’re an ordered series of pull requests that each represent focused layers of your change. With stacks, you can independently review and check each pull request, then merge everything together in one click. No more opening a single large pull request that takes forever to review, or splitting work across multiple branches you have to keep manually rebasing. Stacked PRs(堆叠式拉取请求)将大型变更拆分为小型、易于审查的拉取请求。它们是一系列有序的拉取请求,每个请求都代表了你变更中专注的某一层。通过堆叠,你可以独立审查和检查每个拉取请求,然后一键合并所有内容。无需再提交一个需要耗费大量时间审查的巨型拉取请求,也不必再在多个分支之间手动进行繁琐的变基(rebase)操作。

“We’ve been using GitHub stacked PRs for Next.js for the past few months. It has helped us introduce smaller individual changes while shipping larger features, making it easier to review PRs. – Tim Neutkens, NextJS lead, Vercel” “过去几个月,我们一直在 Next.js 中使用 GitHub 的 Stacked PRs。它帮助我们在交付大型功能的同时引入更小的独立变更,使 PR 审查变得更加容易。—— Tim Neutkens,Vercel NextJS 负责人”

With stacked pull requests, teams can: 使用堆叠式拉取请求,团队可以:

  • Keep large changes moving by reviewing short, narrowly scoped pull requests in parallel. 通过并行审查简短、范围明确的拉取请求,保持大型变更的推进速度。
  • Maintain quality across every layer by using focused pull request reviews alongside existing branch protections to protect main. 通过结合专注的拉取请求审查与现有的分支保护机制来保护主分支,从而确保每一层的代码质量。
  • Merge one, some, or all by landing an entire stack altogether or individual layers one at a time. 通过一次性合并整个堆叠或逐层合并,灵活选择合并一个、部分或全部请求。

And because stacked pull requests are built into GitHub, your existing reviews, checks, and merge requirements all work out of the box. 由于堆叠式拉取请求是内置于 GitHub 中的,你现有的审查、检查和合并要求都可以直接使用,无需额外配置。

“The new Github Stacked PRs preview is incredible. Landing 5 stacked PRs directly to a merge queue all at once! A+++! This removes so much friction (and the gh cli tools + agent skill help a ton)” – John Resig, creator, jQuery “GitHub 新推出的 Stacked PRs 预览版太棒了。可以直接将 5 个堆叠的 PR 一次性提交到合并队列!满分好评!这消除了大量的阻力(而且 gh CLI 工具和 Agent 技能也提供了极大的帮助)。”—— John Resig,jQuery 创建者

Get started with the CLI extension

使用 CLI 扩展开始体验

Install the CLI extension and create your first stack in under a minute: 安装 CLI 扩展,并在不到一分钟的时间内创建你的第一个堆叠: gh extension install github/gh-stack

Create stacks from your terminal or github.com

从终端或 github.com 创建堆叠

Work with stacks on github.com, the GitHub CLI, the GitHub mobile app, or with a coding agent such as GitHub Copilot using the gh-stack skill. Start with a branch and pull request for your first change. Then add branches and pull requests on top of it; each pull request targets the layer below it. 你可以在 github.com、GitHub CLI、GitHub 移动端 App 上使用堆叠,或者通过使用 gh-stack 技能的 GitHub Copilot 等编码助手进行操作。首先从一个分支和拉取请求开始你的第一次变更,然后在它之上添加分支和拉取请求;每个拉取请求都指向其下方的层级。

Review each layer independently

独立审查每一层

Open any pull request in the stack to review only the diff for that specific layer. Use the stack map at the top of the pull request to see how the change you’re reviewing fits into the larger work. You and your teammates can each review different layers in parallel without blocking further work. 打开堆叠中的任何拉取请求,仅审查该特定层级的差异(diff)。使用拉取请求顶部的堆叠图(stack map),查看你正在审查的变更如何融入整体工作。你和你的团队成员可以并行审查不同的层级,而不会阻塞后续工作。

“AI has made TED’s developers dramatically more productive, but that created a new bottleneck: PRs were growing large enough that reviewers were struggling. Stacked PRs help to solve that. By breaking large changes into small, dependency-ordered pieces, review happens in smaller logical chunks – not just faster PR reviews, but more accurate ones. Stacked PRs tighten our feedback loop and help get stable code to ted.com faster.” – Andy Merryman, CTO, TED “人工智能极大地提高了 TED 开发人员的生产力,但这产生了一个新的瓶颈:PR 变得越来越大,审查人员感到力不从心。Stacked PRs 解决了这个问题。通过将大型变更拆分为小的、按依赖顺序排列的部分,审查可以在更小的逻辑块中进行——这不仅加快了 PR 审查速度,还提高了准确性。Stacked PRs 加快了我们的反馈循环,并帮助我们更快地将稳定的代码交付到 ted.com。”—— Andy Merryman,TED 首席技术官

Merge everything in a single click

一键合并所有内容

Merge the latest ready pull request to land it and every unmerged layer below it in one single operation. To land part of a stack, merge one or more lower layers—the pull requests above it stay open and automatically rebase and retarget. Your existing branch protections and required checks still govern what reaches main. 合并最新的就绪拉取请求,即可通过单次操作将其及其下方所有未合并的层级一并合入。若要合入堆叠的一部分,只需合并一个或多个较低的层级——其上方的拉取请求将保持打开状态,并自动进行变基和重定向。你现有的分支保护和必要检查仍然会管控进入主分支的内容。

“A big change used to mean one giant PR nobody wanted to review. Now it’s a stack of small ones reviewers can actually follow, and the whole stack merges in one shot. It stopped feeling like a tool on top of GitHub and started feeling like GitHub.” – Mayank Saini, connectivity engineer, WHOOP “过去,一个大的变更意味着一个没人愿意审查的巨型 PR。现在,它变成了一堆审查人员真正能跟进的小型 PR,而且整个堆叠可以一次性合并。它不再感觉像是 GitHub 之上的一个工具,而感觉就像是 GitHub 本身的一部分。”—— Mayank Saini,WHOOP 连接工程师

Find out more and share your feedback

了解更多并分享你的反馈

Stacked pull requests are rolling out in public preview to all repositories over the coming days. Merge queue support for stacked pull requests is rolling out progressively over the coming weeks. For more information, check out the stacked pull requests documentation, and share your feedback with us in the stacks discussion. 堆叠式拉取请求将在未来几天内向所有仓库推出公开预览版。针对堆叠式拉取请求的合并队列支持将在未来几周内逐步推出。欲了解更多信息,请查看堆叠式拉取请求文档,并在堆叠讨论区与我们分享你的反馈。