I forked a project on github and am successfully making changes to my local master and pushing to origin on github. I want to send a pull request, but only want to include the last commit. The pull request UI on github.com shows the last 9 commits and I don't know how to filter that down.
I was trying to understand if I should create a new local branch, check that out and somehow reset or rebase to upstream? Then apply my last commit from my master by id to the new local branch and use that for the pull request?
I'm trying to get the concepts right and figure out the right command lines to do what I need.
You need to basically create a new branch & cherry-pick the commits you want to add to it.
Note: you might need these before the checkout/cherry-pick commands
git remote add upstream <git repository>
git remote update
git checkout -b <new-branch-name> upstream/master
git cherry-pick <SHA hash of commit>
git push origin <new-branch-name>
Afterwards, you will see <new-branch-name>
branch on github, switch to it and can submit the pull request with the changes you want.
I also need to
git remote add upstream <git repository>
andgit remote update
before running git checkout -b upstream upstream/master.This works, but is not how you are supposed to do it, because now your upstream branch and upstream/master are different and will always be different if merging your pull request is not the first thing upstream does. For that reason you should prefer doing stackoverflow.com/a/5256304/1904815.
To elaborate: This isn't a technical problem, but a logical one. When you want to do anything with upstream (like merging from there) you need to add a branch "real-upstream" or reset your upstream (leaving no local branch for your pull request for additional changes).
Why on earth do I need an extra branch, only to create a PR for a single changed line of code?! Did anyone at github think this through?
@JonHanna No... why do you have to merge a branch at all? Why can't you just merge a commit?