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.
21 It is possible to create branches that starts with `users/<username>/`, however this is
22 intended to be able to support "stacked" pull-request. Do not create any branches in the
23 llvm/llvm-project repository otherwise, please use a fork (see below). User branches that
24 aren't associated with a pull-request **will be deleted**.
28 The LLVM project is using GitHub Pull Requests for Code Reviews. This document
29 describes the typical workflow of creating a Pull Request and getting it reviewed
30 and accepted. This is meant as an overview of the GitHub workflow, for complete
31 documentation refer to `GitHub's documentation <https://docs.github.com/pull-requests>`_.
35 You can interact with GitHub in several ways: via git command line tools,
36 the web browser, `GitHub Desktop <https://desktop.github.com/>`_, or the
37 `GitHub CLI <https://cli.github.com>`_. This guide will cover the git command line
38 tools and the GitHub CLI. The GitHub CLI (`gh`) will be most like the `arc` workflow and
41 Creating Pull Requests
42 ----------------------
43 Keep in mind that when creating a pull request, it should generally only contain one
44 self-contained commit initially.
45 This makes it easier for reviewers to understand the introduced changes and
46 provide feedback. It also helps maintain a clear and organized commit history
47 for the project. If you have multiple changes you want to introduce, it's
48 recommended to create separate pull requests for each change.
50 Create a local branch per commit you want to submit and then push that branch
51 to your `fork <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks>`_
52 of the llvm-project and
53 `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 As GitHub uses the first line of the commit message truncated to 72 characters
55 as the pull request title, you may have to edit to reword or to undo this
58 Creating Pull Requests with GitHub CLI
59 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60 With the CLI it's enough to create the branch locally and then run:
66 When prompted select to create and use your own fork and follow
67 the instructions to add more information needed.
71 When you let the GitHub CLI create a fork of llvm-project to
72 your user, it will change the git "remotes" so that "origin" points
73 to your fork and "upstream" points to the main llvm-project repository.
75 Updating Pull Requests
76 ----------------------
77 In order to update your pull request, the only thing you need to do is to push
78 your new commits to the branch in your fork. That will automatically update
81 When updating a pull request, you should push additional "fix up" commits to
82 your branch instead of force pushing. This makes it easier for GitHub to
83 track the context of previous review comments. Consider using the
84 `built-in support for fixups <https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt>`_
87 If you do this, you must squash and merge before landing the PR and
88 you must use the pull request title and description as the commit message.
89 You can do this manually with an interactive git rebase or with GitHub's
90 built-in tool. See the section about landing your fix below.
92 When pushing to your branch, make sure you push to the correct fork. Check your
99 And make sure you push to the remote that's pointing to your fork.
101 Rebasing Pull Requests and Force Pushes
102 ---------------------------------------
103 In general, you should avoid rebasing a Pull Request and force pushing to the
104 branch that's the root of the Pull Request during the review. This action will
105 make the context of the old changes and comments harder to find and read.
107 Sometimes, a rebase might be needed to update your branch with a fix for a test
108 or in some dependent code.
110 After your PR is reviewed and accepted, you want to rebase your branch to ensure
111 you won't encounter merge conflicts when landing the PR.
115 When your PR has been accepted you can use the web interface to land your change.
116 If you have created multiple commits to address feedback at this point you need
117 to consolidate those commits into one commit. There are two different ways to
120 `Interactive rebase <https://git-scm.com/docs/git-rebase#_interactive_mode>`_
121 with fixup's. This is the recommended method since you can control the final
122 commit message and inspect that the final commit looks as you expect. When
123 your local state is correct, remember to force-push to your branch and press
124 the merge button afterwards.
126 Use the button `Squash and merge` in GitHub's web interface, if you do this
127 remember to review the commit message when prompted.
129 Afterwards you can select the option `Delete branch` to delete the branch
132 You can also merge via the CLI by switching to your branch locally and run:
136 gh pr merge --squash --delete-branch
138 If you observe an error message from the above informing you that your pull
139 request is not mergeable, then that is likely because upstream has been
140 modified since your pull request was authored in a way that now results in a
141 merge conflict. You must first resolve this merge conflict in order to merge
142 your pull request. In order to do that:
147 git rebase upstream/main
149 Then fix the source files causing merge conflicts and make sure to rebuild and
150 retest the result. Then:
154 git add <files with resolved merge conflicts>
155 git rebase --continue
157 Finally, you'll need to force push to your branch one more time before you can
163 gh pr merge --squash --delete-branch
165 This force push may ask if you intend to push hundreds, or potentially
166 thousands of patches (depending on how long it's been since your pull request
167 was initially authored vs. when you intended to merge it). Since you're pushing
168 to a branch in your fork, this is ok and expected. Github's UI for the pull
169 request will understand that you're rebasing just your patches, and display
170 this result correctly with a note that a force push did occur.
173 Checking out another PR locally
174 -------------------------------
175 Sometimes you want to review another person's PR on your local machine to run
176 tests or inspect code in your preferred editor. This is easily done with the
181 gh pr checkout <PR Number>
183 This is also possible with the web interface and the normal git command line
184 tools, but the process is a bit more complicated. See GitHub's
185 `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>`_
188 Example Pull Request with GitHub CLI
189 ====================================
190 Here is an example for creating a Pull Request with the GitHub CLI:
195 gh repo clone llvm/llvm-project
197 # Switch to the repo and create a new branch
199 git switch -c my_change
201 # Create your changes
204 # Don't forget clang-format
207 # and don't forget running your tests
210 # Commit, use a good commit message
213 # Create the PR, select to use your own fork when prompted.
214 # If you don't have a fork, gh will create one for you.
217 # If you get any review comments, come back to the branch and
222 # Commit your changes
223 git commit file.cpp -m "Code Review adjustments"
226 git clang-format HEAD~
228 # Recommit if any formatting changes
229 git commit -a --amend
231 # Push your changes to your fork branch, be mindful of
232 # your remotes here, if you don't remember what points to your
233 # fork, use git remote -v to see. Usually origin points to your
234 # fork and upstream to llvm/llvm-project
235 git push origin my_change
237 Before merging the PR, it is recommended that you rebase locally and re-run test
242 # Add upstream as a remote (if you don't have it already)
243 git remote add upstream https://github.com/llvm/llvm-project.git
245 # Make sure you have all the latest changes
246 git fetch upstream && git rebase -i upstream/main
248 # Make sure tests pass with latest changes and your change
251 # Push the rebased changes to your fork.
252 git push origin my_change -f
255 gh pr merge --squash --delete-branch
258 See more in-depth information about how to contribute in the following documentation:
260 * :doc:`Contributing`
261 * :doc:`MyFirstTypoFix`
263 Example Pull Request with git
264 ====================================
266 Instead of using the GitHub CLI to create a PR, you can push your code to a
267 remote branch on your fork and create the PR to upstream using the GitHub web
270 Here is an example of making a PR using git and the GitHub web interface:
272 First follow the instructions to [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo?tool=webui#forking-a-repository).
274 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).
276 Once you've cloned your forked repository,
280 # Switch to the forked repo
283 # Create a new branch
284 git switch -c my_change
286 # Create your changes
289 # Don't forget clang-format
292 # and don't forget running your tests
295 # Commit, use a good commit message
298 # Push your changes to your fork branch, be mindful of
299 # your remotes here, if you don't remember what points to your
300 # fork, use git remote -v to see. Usually origin points to your
301 # fork and upstream to llvm/llvm-project
302 git push origin my_change
304 Navigate to the URL printed to the console from the git push command in the last step.
305 Create a pull request from your branch to llvm::main.
309 # If you get any review comments, come back to the branch and
314 # Commit your changes
315 git commit file.cpp -m "Code Review adjustments"
318 git clang-format HEAD~
320 # Recommit if any formatting changes
321 git commit -a --amend
323 # Re-run tests and make sure nothing broke.
326 # Push your changes to your fork branch, be mindful of
327 # your remotes here, if you don't remember what points to your
328 # fork, use git remote -v to see. Usually origin points to your
329 # fork and upstream to llvm/llvm-project
330 git push origin my_change
332 Before merging the PR, it is recommended that you rebase locally and re-run test
337 # Add upstream as a remote (if you don't have it already)
338 git remote add upstream https://github.com/llvm/llvm-project.git
340 # Make sure you have all the latest changes
341 git fetch upstream && git rebase -i upstream/main
343 # Make sure tests pass with latest changes and your change
346 # Push the rebased changes to your fork.
347 git push origin my_change -f
349 Once your PR is approved, rebased, and tests are passing, click `Squash and
350 Merge` on your PR in the GitHub web interface.
352 See more in-depth information about how to contribute in the following documentation:
354 * :doc:`Contributing`
355 * :doc:`MyFirstTypoFix`
360 Backporting Fixes to the Release Branches
361 -----------------------------------------
362 You can use special comments on issues to make backport requests for the
363 release branches. This is done by making a comment containing one of the
364 following commands on any issue that has been added to one of the "X.Y.Z Release"
369 /cherry-pick <commit> <commit> <...>
371 This command takes one or more git commit hashes as arguments and will attempt
372 to cherry-pick the commit(s) to the release branch. If the commit(s) fail to
373 apply cleanly, then a comment with a link to the failing job will be added to
374 the issue. If the commit(s) do apply cleanly, then a pull request will
375 be created with the specified commits.
379 /branch <owner>/<repo>/<branch>
381 This command will create a pull request against the latest release branch using
382 the <branch> from the <owner>/<repo> repository. <branch> cannot contain any
383 forward slash '/' characters.