9 The LLVM Project uses `GitHub <https://github.com/>`_ for
10 `Source Code <https://github.com/llvm/llvm-project>`_,
11 `Releases <https://github.com/llvm/llvm-project/releases>`_,
12 `Issue Tracking <https://github.com/llvm/llvm-project/issues>`_., and
13 `Code Reviews <https://github.com/llvm/llvm-project/pulls>`_.
15 This page describes how the LLVM Project users and developers can
16 participate in the project using GitHub.
20 Do not create any branches in the llvm/llvm-project repository. This repository
21 is reserved for official project branches only. We may relax this rule in
22 the future if needed to support "stacked" pull request, but in that case only
23 branches being used for "stacked" pull requests will be allowed.
27 The LLVM project is using GitHub Pull Requests for Code Reviews. This document
28 describes the typical workflow of creating a Pull Request and getting it reviewed
29 and accepted. This is meant as an overview of the GitHub workflow, for complete
30 documentation refer to `GitHub's documentation <https://docs.github.com/pull-requests>`_.
34 You can interact with GitHub in several ways: via git command line tools,
35 the web browser, `GitHub Desktop <https://desktop.github.com/>`_, or the
36 `GitHub CLI <https://cli.github.com>`_. This guide will cover the git command line
37 tools and the GitHub CLI. The GitHub CLI (`gh`) will be most like the `arc` workflow and
40 Creating Pull Requests
41 ----------------------
42 Keep in mind that when creating a pull request, it should generally only contain one
43 self-contained commit initially.
44 This makes it easier for reviewers to understand the introduced changes and
45 provide feedback. It also helps maintain a clear and organized commit history
46 for the project. If you have multiple changes you want to introduce, it's
47 recommended to create separate pull requests for each change.
49 Create a local branch per commit you want to submit and then push that branch
50 to your `fork <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks>`_
51 of the llvm-project and
52 `create a pull request from the fork <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork>`_.
54 Creating Pull Requests with GitHub CLI
55 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56 With the CLI it's enough to create the branch locally and then run:
62 When prompted select to create and use your own fork and follow
63 the instructions to add more information needed.
67 When you let the GitHub CLI create a fork of llvm-project to
68 your user, it will change the git "remotes" so that "origin" points
69 to your fork and "upstream" points to the main llvm-project repository.
71 Updating Pull Requests
72 ----------------------
73 In order to update your pull request, the only thing you need to do is to push
74 your new commits to the branch in your fork. That will automatically update
77 When updating a pull request, you should push additional "fix up" commits to
78 your branch instead of force pushing. This makes it easier for GitHub to
79 track the context of previous review comments. Consider using the
80 `built-in support for fixups <https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt>`_
83 If you do this, you must squash and merge before landing the PR and
84 you must use the pull request title and description as the commit message.
85 You can do this manually with an interactive git rebase or with GitHub's
86 built-in tool. See the section about landing your fix below.
88 When pushing to your branch, make sure you push to the correct fork. Check your
95 And make sure you push to the remote that's pointing to your fork.
97 Rebasing Pull Requests and Force Pushes
98 ---------------------------------------
99 In general, you should avoid rebasing a Pull Request and force pushing to the
100 branch that's the root of the Pull Request during the review. This action will
101 make the context of the old changes and comments harder to find and read.
103 Sometimes, a rebase might be needed to update your branch with a fix for a test
104 or in some dependent code.
106 After your PR is reviewed and accepted, you want to rebase your branch to ensure
107 you won't encounter merge conflicts when landing the PR.
111 When your PR has been accepted you can use the web interface to land your change.
112 If you have created multiple commits to address feedback at this point you need
113 to consolidate those commits into one commit. There are two different ways to
116 `Interactive rebase <https://git-scm.com/docs/git-rebase#_interactive_mode>`_
117 with fixup's. This is the recommended method since you can control the final
118 commit message and inspect that the final commit looks as you expect. When
119 your local state is correct, remember to force-push to your branch and press
120 the merge button afterwards.
122 Use the button `Squash and merge` in GitHub's web interface, if you do this
123 remember to review the commit message when prompted.
125 Afterwards you can select the option `Delete branch` to delete the branch
128 You can also merge via the CLI by switching to your branch locally and run:
132 gh pr merge --squash --delete-branch
134 If you observe an error message from the above informing you that your pull
135 request is not mergeable, then that is likely because upstream has been
136 modified since your pull request was authored in a way that now results in a
137 merge conflict. You must first resolve this merge conflict in order to merge
138 your pull request. In order to do that:
143 git rebase upstream/main
145 Then fix the source files causing merge conflicts and make sure to rebuild and
146 retest the result. Then:
150 git add <files with resolved merge conflicts>
151 git rebase --continue
153 Finally, you'll need to force push to your branch one more time before you can
159 gh pr merge --squash --delete-branch
161 This force push may ask if you intend to push hundreds, or potentially
162 thousands of patches (depending on how long it's been since your pull request
163 was initially authored vs. when you intended to merge it). Since you're pushing
164 to a branch in your fork, this is ok and expected. Github's UI for the pull
165 request will understand that you're rebasing just your patches, and display
166 this result correctly with a note that a force push did occur.
169 Checking out another PR locally
170 -------------------------------
171 Sometimes you want to review another person's PR on your local machine to run
172 tests or inspect code in your preferred editor. This is easily done with the
177 gh pr checkout <PR Number>
179 This is also possible with the web interface and the normal git command line
180 tools, but the process is a bit more complicated. See GitHub's
181 `documentation <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally?platform=linux&tool=webui#modifying-an-inactive-pull-request-locally>`_
184 Example Pull Request with GitHub CLI
185 ====================================
186 Here is an example for creating a Pull Request with the GitHub CLI:
191 gh repo clone llvm/llvm-project
193 # Switch to the repo and create a new branch
195 git switch -c my_change
197 # Create your changes
200 # Don't forget clang-format
203 # and don't forget running your tests
206 # Commit, use a good commit message
209 # Create the PR, select to use your own fork when prompted.
210 # If you don't have a fork, gh will create one for you.
213 # If you get any review comments, come back to the branch and
218 # Commit your changes
219 git commit file.cpp -m "Code Review adjustments"
222 git clang-format HEAD~
224 # Recommit if any formatting changes
225 git commit -a --amend
227 # Push your changes to your fork branch, be mindful of
228 # your remotes here, if you don't remember what points to your
229 # fork, use git remote -v to see. Usually origin points to your
230 # fork and upstream to llvm/llvm-project
231 git push origin my_change
233 Before merging the PR, it is recommended that you rebase locally and re-run test
238 # Add upstream as a remote (if you don't have it already)
239 git remote add upstream https://github.com/llvm/llvm-project.git
241 # Make sure you have all the latest changes
242 git fetch upstream && git rebase -i upstream/main
244 # Make sure tests pass with latest changes and your change
247 # Push the rebased changes to your fork.
248 git push origin my_change -f
251 gh pr merge --squash --delete-branch
254 See more in-depth information about how to contribute in the following documentation:
256 * :doc:`Contributing`
257 * :doc:`MyFirstTypoFix`
259 Example Pull Request with git
260 ====================================
262 Instead of using the GitHub CLI to create a PR, you can push your code to a
263 remote branch on your fork and create the PR to upstream using the GitHub web
266 Here is an example of making a PR using git and the GitHub web interface:
268 First follow the instructions to [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo?tool=webui#forking-a-repository).
270 Next follow the instructions to [clone your forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo?tool=webui#cloning-your-forked-repository).
272 Once you've cloned your forked repository,
276 # Switch to the forked repo
279 # Create a new branch
280 git switch -c my_change
282 # Create your changes
285 # Don't forget clang-format
288 # and don't forget running your tests
291 # Commit, use a good commit message
294 # Push your changes to your fork branch, be mindful of
295 # your remotes here, if you don't remember what points to your
296 # fork, use git remote -v to see. Usually origin points to your
297 # fork and upstream to llvm/llvm-project
298 git push origin my_change
300 Navigate to the URL printed to the console from the git push command in the last step.
301 Create a pull request from your branch to llvm::main.
305 # If you get any review comments, come back to the branch and
310 # Commit your changes
311 git commit file.cpp -m "Code Review adjustments"
314 git clang-format HEAD~
316 # Recommit if any formatting changes
317 git commit -a --amend
319 # Re-run tests and make sure nothing broke.
322 # Push your changes to your fork branch, be mindful of
323 # your remotes here, if you don't remember what points to your
324 # fork, use git remote -v to see. Usually origin points to your
325 # fork and upstream to llvm/llvm-project
326 git push origin my_change
328 Before merging the PR, it is recommended that you rebase locally and re-run test
333 # Add upstream as a remote (if you don't have it already)
334 git remote add upstream https://github.com/llvm/llvm-project.git
336 # Make sure you have all the latest changes
337 git fetch upstream && git rebase -i upstream/main
339 # Make sure tests pass with latest changes and your change
342 # Push the rebased changes to your fork.
343 git push origin my_change -f
345 Once your PR is approved, rebased, and tests are passing, click `Squash and
346 Merge` on your PR in the GitHub web interface.
348 See more in-depth information about how to contribute in the following documentation:
350 * :doc:`Contributing`
351 * :doc:`MyFirstTypoFix`
356 Backporting Fixes to the Release Branches
357 -----------------------------------------
358 You can use special comments on issues to make backport requests for the
359 release branches. This is done by making a comment containing one of the
360 following commands on any issue that has been added to one of the "X.Y.Z Release"
365 /cherry-pick <commit> <commit> <...>
367 This command takes one or more git commit hashes as arguments and will attempt
368 to cherry-pick the commit(s) to the release branch. If the commit(s) fail to
369 apply cleanly, then a comment with a link to the failing job will be added to
370 the issue. If the commit(s) do apply cleanly, then a pull request will
371 be created with the specified commits.
375 /branch <owner>/<repo>/<branch>
377 This command will create a pull request against the latest release branch using
378 the <branch> from the <owner>/<repo> repository. <branch> cannot contain any
379 forward slash '/' characters.