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.
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 https://github.com/somebodyelses/project.git
Fetch and update the branches of all remote repsitories, here
origin (the clone) and
upstream (the original):
git fetch --all
Create and switch-to a new branch which is based on the upstream branch that would be the destination of the pull request, usually
git checkout -b nameoftheprbr upstream/master
Cherry-pick the commit(s) to be pr'd from your working branch into the just created new branch:
git cherry-pick 076bb8e4c70e3408e6184c6ef97c5099bd511e4a ...
The new branch
nameoftheprbr needs to pushed to your fork (clone) of the project on GitHub:
git push origin HEAD
Before it becomes forgotten, switch back to your current working branch (for example,
git checkout master
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
Discussion on Twitter: 1394514971699073026