⇦ Back to: Review Pull Request | ⇧ Overview | ⇨ Next: Clean up
Once you’ve been given feedback and it’s agreed that your PR is good to be merged into the main branch, it can be merged.
You or someone with the right to write to the repository can click the “Merge pull request” button in the GitHub Pull Request.
It is also possible to carry out merges using the GitHub Desktop application, or the command line, but these may not work if the base branch is protected (see next section). We recommend using the web interface.
<aside> 🍎
It’s good merging etiquette to have the person who authored the PR merge it, if possible. Among other things, this makes it clear to author and repository owner alike, that the author has agency and is responsible for the work they’ve done.
This sometimes isn’t possible, for instance if the person has made the pull-request from a fork. In this case, ensure that the PR really is finished by checking with the author, before you merge it.
As a repository owner, you can enforce that a PR is only merged once it is approved by using branch protection rules.
</aside>
If the people working on the project think that a PR shouldn’t become part of the main branch for whatever reason, then you can close the PR without merging.
Add a comment, then click “Close with comment”. The PR stays in the list of closed PRs, and you can always revisit the conversation and the code associated with it.
Some PRs need splitting into several smaller PRs before they can be properly reviewed and merged.
If the commits were small enough, this is often extremely quick to achieve using the “cherry-pick” function of Git. In this mode, each commit is treated as a “delta” – the small change it applied to the code from before.
We recommend using the GitHub Desktop GUI for this, as selecting commits from the log can be more time consuming.
Start a new branch from “main”.
Go through the commit history from oldest to newest, locating each of the commits which should be included in the new PR.
For each, right click on it and select “Cherry-pick commit”
Check that the result continues to work as you had expected.
<aside> 🍎 It’s good etiquette to use cherry-picking like this to restructure work which someone else has done. It means that the original author will still be credited as the author of the commit, even if someone else actually presses “commit.”
For instructions on how to add co-authors on the command line, see the GitHub Docs on Pull requests
</aside>