Atomic pull requests to an upstream repository on GitHub

You are working on a fork (clone) of somebody else’s project on GitHub. You committed and pushed already some changes to your repository’s master, some of which are irrelevant for the upstream project, and for other commits you would like to submit pull requests. Here we go.

  1. If not already done, from within the local working copy, add the upstream repository to the set of remote repositories to be tracked:
       git remote add upstream
  2. Fetch and update the branches of all remote repsitories, here origin (the clone) and upstream (the original):
       git fetch --all
  3. Create and switch-to a new branch which is based on the upstream branch that would be the destination of the pull request, usually upstream/master:
       git checkout -b nameoftheprbr upstream/master
  4. Cherry-pick the commit(s) to be pr'd from your working branch into the just created new branch:
       git cherry-pick 076bb8e4c70e3408e6184c6ef97c5099bd511e4a ...
  5. The new branch nameoftheprbr needs to pushed to your fork (clone) of the project on GitHub:
       git push origin HEAD
  6. Before it becomes forgotten, switch back to your current working branch (for example, master):
       git checkout master
  7. Finally, login-to your GitHub site, find the new branch and create & submit the pull request.

Copyright © Dr. Rolf Jansen - 2021-03-14 21:23:11