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>`_.
53 As GitHub uses the first line of the commit message truncated to 72 characters
54 as the pull request title, you may have to edit to reword or to undo this
57 Creating Pull Requests with GitHub CLI
58 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59 With the CLI it's enough to create the branch locally and then run:
65 When prompted select to create and use your own fork and follow
66 the instructions to add more information needed.
70 When you let the GitHub CLI create a fork of llvm-project to
71 your user, it will change the git "remotes" so that "origin" points
72 to your fork and "upstream" points to the main llvm-project repository.
74 Updating Pull Requests
75 ----------------------
76 In order to update your pull request, the only thing you need to do is to push
77 your new commits to the branch in your fork. That will automatically update
80 When updating a pull request, you should push additional "fix up" commits to
81 your branch instead of force pushing. This makes it easier for GitHub to
82 track the context of previous review comments. Consider using the
83 `built-in support for fixups <https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt>`_
86 If you do this, you must squash and merge before landing the PR and
87 you must use the pull request title and description as the commit message.
88 You can do this manually with an interactive git rebase or with GitHub's
89 built-in tool. See the section about landing your fix below.
91 When pushing to your branch, make sure you push to the correct fork. Check your
98 And make sure you push to the remote that's pointing to your fork.
100 Rebasing Pull Requests and Force Pushes
101 ---------------------------------------
102 In general, you should avoid rebasing a Pull Request and force pushing to the
103 branch that's the root of the Pull Request during the review. This action will
104 make the context of the old changes and comments harder to find and read.
106 Sometimes, a rebase might be needed to update your branch with a fix for a test
107 or in some dependent code.
109 After your PR is reviewed and accepted, you want to rebase your branch to ensure
110 you won't encounter merge conflicts when landing the PR.
114 When your PR has been accepted you can use the web interface to land your change.
115 If you have created multiple commits to address feedback at this point you need
116 to consolidate those commits into one commit. There are two different ways to
119 `Interactive rebase <https://git-scm.com/docs/git-rebase#_interactive_mode>`_
120 with fixup's. This is the recommended method since you can control the final
121 commit message and inspect that the final commit looks as you expect. When
122 your local state is correct, remember to force-push to your branch and press
123 the merge button afterwards.
125 Use the button `Squash and merge` in GitHub's web interface, if you do this
126 remember to review the commit message when prompted.
128 Afterwards you can select the option `Delete branch` to delete the branch
131 You can also merge via the CLI by switching to your branch locally and run:
135 gh pr merge --squash --delete-branch
137 If you observe an error message from the above informing you that your pull
138 request is not mergeable, then that is likely because upstream has been
139 modified since your pull request was authored in a way that now results in a
140 merge conflict. You must first resolve this merge conflict in order to merge
141 your pull request. In order to do that:
146 git rebase upstream/main
148 Then fix the source files causing merge conflicts and make sure to rebuild and
149 retest the result. Then:
153 git add <files with resolved merge conflicts>
154 git rebase --continue
156 Finally, you'll need to force push to your branch one more time before you can
162 gh pr merge --squash --delete-branch
164 This force push may ask if you intend to push hundreds, or potentially
165 thousands of patches (depending on how long it's been since your pull request
166 was initially authored vs. when you intended to merge it). Since you're pushing
167 to a branch in your fork, this is ok and expected. Github's UI for the pull
168 request will understand that you're rebasing just your patches, and display
169 this result correctly with a note that a force push did occur.
172 Checking out another PR locally
173 -------------------------------
174 Sometimes you want to review another person's PR on your local machine to run
175 tests or inspect code in your preferred editor. This is easily done with the
180 gh pr checkout <PR Number>
182 This is also possible with the web interface and the normal git command line
183 tools, but the process is a bit more complicated. See GitHub's
184 `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>`_
187 Example Pull Request with GitHub CLI
188 ====================================
189 Here is an example for creating a Pull Request with the GitHub CLI:
194 gh repo clone llvm/llvm-project
196 # Switch to the repo and create a new branch
198 git switch -c my_change
200 # Create your changes
203 # Don't forget clang-format
206 # and don't forget running your tests
209 # Commit, use a good commit message
212 # Create the PR, select to use your own fork when prompted.
213 # If you don't have a fork, gh will create one for you.
216 # If you get any review comments, come back to the branch and
221 # Commit your changes
222 git commit file.cpp -m "Code Review adjustments"
225 git clang-format HEAD~
227 # Recommit if any formatting changes
228 git commit -a --amend
230 # Push your changes to your fork branch, be mindful of
231 # your remotes here, if you don't remember what points to your
232 # fork, use git remote -v to see. Usually origin points to your
233 # fork and upstream to llvm/llvm-project
234 git push origin my_change
236 Before merging the PR, it is recommended that you rebase locally and re-run test
241 # Add upstream as a remote (if you don't have it already)
242 git remote add upstream https://github.com/llvm/llvm-project.git
244 # Make sure you have all the latest changes
245 git fetch upstream && git rebase -i upstream/main
247 # Make sure tests pass with latest changes and your change
250 # Push the rebased changes to your fork.
251 git push origin my_change -f
254 gh pr merge --squash --delete-branch
257 See more in-depth information about how to contribute in the following documentation:
259 * :doc:`Contributing`
260 * :doc:`MyFirstTypoFix`
262 Example Pull Request with git
263 ====================================
265 Instead of using the GitHub CLI to create a PR, you can push your code to a
266 remote branch on your fork and create the PR to upstream using the GitHub web
269 Here is an example of making a PR using git and the GitHub web interface:
271 First follow the instructions to [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo?tool=webui#forking-a-repository).
273 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).
275 Once you've cloned your forked repository,
279 # Switch to the forked repo
282 # Create a new branch
283 git switch -c my_change
285 # Create your changes
288 # Don't forget clang-format
291 # and don't forget running your tests
294 # Commit, use a good commit message
297 # Push your changes to your fork branch, be mindful of
298 # your remotes here, if you don't remember what points to your
299 # fork, use git remote -v to see. Usually origin points to your
300 # fork and upstream to llvm/llvm-project
301 git push origin my_change
303 Navigate to the URL printed to the console from the git push command in the last step.
304 Create a pull request from your branch to llvm::main.
308 # If you get any review comments, come back to the branch and
313 # Commit your changes
314 git commit file.cpp -m "Code Review adjustments"
317 git clang-format HEAD~
319 # Recommit if any formatting changes
320 git commit -a --amend
322 # Re-run tests and make sure nothing broke.
325 # Push your changes to your fork branch, be mindful of
326 # your remotes here, if you don't remember what points to your
327 # fork, use git remote -v to see. Usually origin points to your
328 # fork and upstream to llvm/llvm-project
329 git push origin my_change
331 Before merging the PR, it is recommended that you rebase locally and re-run test
336 # Add upstream as a remote (if you don't have it already)
337 git remote add upstream https://github.com/llvm/llvm-project.git
339 # Make sure you have all the latest changes
340 git fetch upstream && git rebase -i upstream/main
342 # Make sure tests pass with latest changes and your change
345 # Push the rebased changes to your fork.
346 git push origin my_change -f
348 Once your PR is approved, rebased, and tests are passing, click `Squash and
349 Merge` on your PR in the GitHub web interface.
351 See more in-depth information about how to contribute in the following documentation:
353 * :doc:`Contributing`
354 * :doc:`MyFirstTypoFix`
359 Backporting Fixes to the Release Branches
360 -----------------------------------------
361 You can use special comments on issues to make backport requests for the
362 release branches. This is done by making a comment containing one of the
363 following commands on any issue that has been added to one of the "X.Y.Z Release"
368 /cherry-pick <commit> <commit> <...>
370 This command takes one or more git commit hashes as arguments and will attempt
371 to cherry-pick the commit(s) to the release branch. If the commit(s) fail to
372 apply cleanly, then a comment with a link to the failing job will be added to
373 the issue. If the commit(s) do apply cleanly, then a pull request will
374 be created with the specified commits.
378 /branch <owner>/<repo>/<branch>
380 This command will create a pull request against the latest release branch using
381 the <branch> from the <owner>/<repo> repository. <branch> cannot contain any
382 forward slash '/' characters.