Merging pull requests (PRs) in GitHub is a key part of the collaborative development process, allowing multiple contributions to be integrated into a single codebase. This guide will explain how to merge PRs in GitHub, including merging into different branches and utilizing Graphite's Merge when ready feature for automatic merging.
How to merge a pull request in GitHub
Review the pull request:
- Ensure the PR has been thoroughly reviewed and approved. Check that all checks, such as continuous integration tests, have passed.
Merge the PR:
- Navigate to the pull request page.
- Below the PR details, you will find the Merge pull request button. Click on it once all requirements are met.
Choose a merge strategy:
- GitHub offers several merge strategies:
- Create a merge commit: Combines the commits from the source branch into the target branch as a single merge commit.
- Squash and merge: Condenses all commits into one commit before merging.
- Rebase and merge: Replays the commits from the source branch onto the target branch in a linear history.
- GitHub offers several merge strategies:
Confirm the merge:
- After selecting your merge strategy, click Confirm merge. Add a commit message if required.
How to merge a pull request into another branch
Change the base branch:
- Before merging, you can change the target branch by clicking Edit next to the base branch at the top of the PR.
- Select the branch you want to merge into from the dropdown menu.
Follow the standard merge process:
- Review and merge the PR as described above.
How to merge an approved pull request in GitHub
- Once a pull request is approved, follow the normal merge process. Ensure that all necessary approvals are in place, and no additional changes are needed before merging.
Merge pull request manually
- If you need to perform a manual merge, such as resolving conflicts or combining multiple branches:
- Check out the target branch locally using
git checkout
. - Merge the PR branch into the target using
git merge <branch-name>
. - Resolve any conflicts that appear.
- Commit the changes and push them back to GitHub.
- Check out the target branch locally using
Merge pull request from another branch
- To merge changes from another branch into your current branch:
- Checkout the branch you want to merge changes into.
- Use
git merge <other-branch>
to combine the branches.
Graphite's Merge when ready feature
Graphite offers a convenient feature called Merge when ready, which automates the merging process once all branch protection rules have been met. This is similar to GitHub's automerge but specifically tailored for Graphite's environment.
To enable Merge when ready:
- Navigate to the PR page in Graphite.
- Toggle on Merge when ready next to the merge button on the PR page.
- Graphite will automatically merge the PR once it becomes mergeable and all conditions are met.
Summary
This guide has explored several strategies for merging pull requests in GitHub, ensuring you can smoothly integrate team contributions and enhance your project’s development flow, with additional support from Graphite’s Merge when ready feature for automation and ease.