[llvm] [Docs] Add example of making a PR with git and GitHub web interface (PR #65393)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 5 13:36:37 PDT 2023


================
@@ -207,6 +207,76 @@ See more in-depth information about how to contribute in the following documenta
 * :doc:`Contributing`
 * :doc:`MyFirstTypoFix`
 
+Example Pull Request with git
+====================================
+
+Instead of using the GitHub CLI to create a PR, you can push your code to a
+remote branch on your fork and create the PR to upstream using the GitHub web
+interface.
+
+Here is an example of making a PR using git and the GitHub web interface:
+
+First follow the instructions to [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo?tool=webui#forking-a-repository).
+
+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).
+
+Once you've cloned your forked repository,
+
+::
+
+  # Switch to the forked repo and create a new branch
+  cd llvm-project
+  git switch -c my_change
+
+  # Create your changes
+  $EDITOR file.cpp
+
+  # Don't forget clang-format
+  git clang-format
+
+  # and don't forget running your tests
+  ninja check-llvm
+
+  # Commit, use a good commit message
+  git commit file.cpp
+
+  # Push your changes to your fork branch, be mindful of
+  # your remotes here, if you don't remember what points to your
+  # fork, use git remote -v to see. Usually origin points to your
+  # fork and upstream to llvm/llvm-project
+  git push origin my_change
+
+Now back on the GitHub web interface, navigate to your fork and create a pull
+request from your branch to llvm::main.
+
+::
+
+  # If you get any review comments, come back to the branch and
+  # adjust them.
+  git switch my_change
+  $EDITOR file.cpp
+
+  # Commit your changes
+  git commit file.cpp -m "Code Review adjustments"
+
+  # Push your changes to your fork branch, be mindful of
+  # your remotes here, if you don't remember what points to your
+  # fork, use git remote -v to see. Usually origin points to your
+  # fork and upstream to llvm/llvm-project
+  git push origin my_change
+
+  # When your PR is accepted, you can now rebase it and make sure
+  # you have all the latest changes.
+  git rebase -i origin/main
----------------
michaelmaitland wrote:

I agree with you that we do not need to rebase to avoid merge conflicts unless prompted by GitHub. Maybe it would be nice if we added a step to rebase if GitHub says there are conflicts.

I concede that it may be optional to rebase when there are no conflicts, running ninja, and then merging PR. But I think it is good practice, since it will prevent failures caused by the interaction of the PR and commits on main that the PR has not seen.

Maybe we can reword the example here to note that it is not required, but good practice. WDYT?

https://github.com/llvm/llvm-project/pull/65393


More information about the llvm-commits mailing list