Skip to content

Commit 7dce16a

Browse files
authored
[docs][GitHub] Update docs for stacked PRs (#132424)
1 parent 04676c6 commit 7dce16a

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

llvm/docs/GitHub.rst

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Before your first PR
2121
Please ensure that you have set a valid email address in your GitHub account,
2222
see :ref:`github-email-address`.
2323

24+
.. _github_branches:
25+
2426
Branches
2527
========
2628

@@ -29,8 +31,80 @@ intended to be able to support "stacked" pull-request. Do not create any branche
2931
llvm/llvm-project repository otherwise, please use a fork (see below). User branches that
3032
aren't associated with a pull-request **will be deleted**.
3133

34+
Stacked Pull Requests
35+
=====================
36+
37+
To separate related changes or to break down a larger PR into smaller, reviewable
38+
pieces, use "stacked pull requests" — this helps make the review process
39+
smoother.
40+
41+
.. note::
42+
The LLVM Project monorepo on GitHub is configured to always use "Squash and
43+
Merge" as the pull request merge option. As a result, each PR results in
44+
exactly one commit being merged into the project.
45+
46+
This means that stacked pull requests are the only available option for
47+
landing a series of related changes. In contrast, submitting a PR with
48+
multiple commits and merging them as-is (without squashing) is not supported
49+
in LLVM.
50+
51+
While GitHub does not natively support stacked pull requests, there are several
52+
common alternatives.
53+
54+
To illustrate, assume that you are working on two branches in your fork of the
55+
``llvm/llvm-project`` repository, and you want to eventually merge both into
56+
``main``:
57+
58+
- `feature_1`, which contains commit `feature_commit_1`
59+
- `feature_2`, which contains commit `feature_commit_2` and depends on
60+
`feature_1` (so it also includes `feature_commit_1`)
61+
62+
Your options are as follows:
63+
64+
#. Two PRs with a dependency note
65+
66+
Create PR_1 for `feature_1` and PR_2 for `feature_2`. In PR_2, include a
67+
note in the PR summary indicating that it depends on PR_1 (e.g.,
68+
“Depends on #PR_1”).
69+
70+
To make review easier, make it clear which commits are part of the base PR
71+
and which are new, e.g. "The first N commits are from the base PR". This
72+
helps reviewers focus only on the incremental changes.
73+
74+
#. Use user branches in ``llvm/llvm-project``
75+
76+
Create user branches in the main repository, as described
77+
:ref:`above<github_branches>`. Then:
78+
79+
- Open a pull request from `users/<username>/feature_1` → `main`
80+
- Open another from `users/<username>/feature_2` → `users/<username>/feature_1`
81+
82+
This approach allows GitHub to display clean, incremental diffs for each PR
83+
in the stack, making it much easier for reviewers to see what has changed at
84+
each step. Once `feature_1` is merged, you can rebase and re-target
85+
`feature_2` to `main`.
86+
87+
#. Use a stacked PR tool
88+
89+
Use tools like SPR or Graphite (described below) to automate managing
90+
stacked PRs. These tools are also based on using user branches
91+
in ``llvm/llvm-project``.
92+
93+
.. note::
94+
When not using user branches, GitHub will not display proper diffs for
95+
subsequent PRs in a stack. Instead, it will show a combined diff that
96+
includes all commits from earlier PRs.
97+
98+
As described in the first option above, in such cases it is the PR author’s
99+
responsibility to clearly indicate which commits are relevant to the
100+
current PR. For example: “The first N commits are from the base PR.”
101+
102+
You can avoid this issue by using user branches directly in the
103+
``llvm/llvm-project`` repository.
104+
105+
32106
Using Graphite for stacked Pull Requests
33-
========================================
107+
----------------------------------------
34108

35109
`Graphite <https://app.graphite.dev/>`_ is a stacked pull request tool supported
36110
by the LLVM repo (the other being `reviewable.io <https://reviewable.io>`_).

0 commit comments

Comments
 (0)