GitHub Pull Request for a Single Commit

Sometimes you want to create a pull request for a single commit in a fork rather than for all the differences to the main repository. Unfortunately the GitHub pull request interface doesn’t support this. There is a pretty easy workaround though by creating an additional branch and cherry picking the commit(s) you wan’t to send a pull request for.

First create an empty branch using the SHA of the last commit when your fork was still in sync. You can find this SHA easily by trying to create a pull request for your fork and selecting the SHA of the oldest commit:

git checkout -b feature 1fe4892^1

Next sync with the main repository:

git pull official master

Cherry pick the commit(s) you want to send a pull request for:

git cherry-pick 5e99125

Push the new branch to GitHub:

git push origin feature

After this is done you can select the newly pushed branch from the “compare” dropdown when creating the pull request.

If you want to clean up after the pull request has been accepted you can simply run these 3 commands remove the temporary branches locally and remotely:

git checkout master
git -D feature
git push origin :feature

I'm available for contracting work. Check out my LinkedIn profile and my portfolio page for an overview of my skills and experience. If you are interested in working with me please use the contact form to get in touch.

GitHub Pull Request for a Single Commit

Leave a Reply

Your email address will not be published. Required fields are marked *