How to Merge a Pull Request on GitHub

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 MethodDescription
Create a merge commit (default)Merges the entire branch history as one commit. Ideal for preserving full commit history.
Squash and mergeCombines all commits into a single commit. Great for cleaning up messy commit histories.
Rebase and mergeRewrites 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

StepAction
1. Open PRGo to repo → Pull Requests → Select PR
2. ReviewCheck files, comments, and status checks
3. Click MergeUse green “Merge pull request” button
4. Choose methodMerge commit, squash, or rebase
5. ConfirmConfirm merge, optionally delete branch
Sharing Is Caring:

Leave a Comment