A pull request (PR) lets contributors propose changes to a codebase. Once reviewed and approved, maintainers can merge the pull request into the base branch (often main
or develop
).
✅ Prerequisites
- You must have write or admin access to the repository.
- The pull request must be open, and ideally:
- All checks (tests, CI) are passing
- There are no merge conflicts
- It has been reviewed and approved (if required)
🧭 Step-by-Step: Merging a Pull Request
1. Open the Pull Request
- Go to the repository on GitHub.
- Click the “Pull requests” tab.
- Select the PR you want to merge.
2. Review the Changes
- Use the “Files changed” tab to review code.
- Read through comments and approvals.
- Check for passing status checks (like GitHub Actions or CI/CD pipelines).
3. Click “Merge Pull Request”
On the PR page, scroll down and click the green “Merge pull request” button.
4. Choose a Merge Method
You’ll be prompted to select one of three options:
Merge Method | Description |
---|---|
Create a merge commit (default) | Merges the entire branch history as one commit. Ideal for preserving full commit history. |
Squash and merge | Combines all commits into a single commit. Great for cleaning up messy commit histories. |
Rebase and merge | Rewrites history to create a linear commit timeline. Best when you want a clean, non-merge history. |
Select the method based on your project’s workflow or team preference.
5. Confirm the Merge
Optionally, edit the commit message. Then click:
Confirm merge
The pull request will be merged into the base branch.
6. Delete the Branch (Optional)
After merging, GitHub gives you the option to:
Delete branch
This is useful for cleaning up stale feature branches after they’re merged.
🧠 Best Practices
- Always review changes and CI results before merging.
- Use squash or rebase for cleaner histories in collaborative projects.
- Protect critical branches with rules (like requiring reviews or passing checks).
📋 Summary
Step | Action |
---|---|
1. Open PR | Go to repo → Pull Requests → Select PR |
2. Review | Check files, comments, and status checks |
3. Click Merge | Use green “Merge pull request” button |
4. Choose method | Merge commit, squash, or rebase |
5. Confirm | Confirm merge, optionally delete branch |