Skip to main content

Merge a Pull Request

After creating and reviewing a Pull Request (PR), the final step in the GitHub workflow is to merge it into the main branch. Merging means integrating your feature branch changes into the base branch — typically main.

Once merged, your updates officially become part of the project 🎉


What Does “Merging” Mean?

In Git and GitHub, merging takes the changes from one branch (like feature/update-ui) and integrates them into another branch (like main).
When you merge a PR, Git combines the commit histories and updates the target branch with your new code.

Step-by-Step: How to Merge a Pull Request

1. Go to the Pull Requests tab

Navigate to your repository on GitHub and click on the Pull requests tab.
You’ll see a list of open PRs.

Example:
https://github.com/<your-username>/<repository-name>/pulls

2. Select the Pull Request you want to merge

Click on the PR you created earlier (for example: Added detailed README).
Here, you’ll see:

  • The PR title and description
  • Files changed
  • Review comments
  • Merge status

3. Review the Merge Status

GitHub automatically checks if the PR can be merged cleanly.
You’ll see one of these messages:

  • This branch has no conflicts with the base branch – safe to merge
  • ⚠️ This branch has conflicts that must be resolved – fix before merging

If there are conflicts, click Resolve conflicts, fix them in the web editor, and commit the changes.

4. Choose a Merge Method

GitHub provides three main merge options:

Merge OptionDescriptionWhen to Use
Merge CommitAdds all commits from the feature branch into the base branch with a single merge commitDefault, keeps full history
Squash and MergeCombines all commits from the branch into one clean commitBest for small feature updates or fixes
Rebase and MergeRewrites the commit history, placing your commits on top of the base branchFor maintaining a linear history

Example (default):

Merge pull request #3 from feature/add-readme

5. Confirm the Merge

Once you’ve chosen a method, click: Merge Pull Request → Confirm Merge

GitHub will integrate your changes and show a success message:

🎉 Pull request successfully merged and closed!

After merging, it’s a good practice to delete your feature branch — it keeps your repository clean. Click Delete branch on GitHub or run this locally:

git branch -d feature/add-readme

If you want to delete the remote branch as well:

git push origin --delete feature/add-readme

Example Workflow Summary

Here’s a full merge process from start to finish:

# 1. Create a new branch
git checkout -b feature/add-readme

# 2. Make changes and commit
git add .
git commit -m "Added detailed README file"

# 3. Push branch to GitHub
git push origin feature/add-readme

# 4. Create a Pull Request on GitHub
# 5. Review → Merge Pull Request
# 6. Delete the feature branch

Troubleshooting Common Merge Issues

ProblemCauseSolution
Merge conflictsBoth branches edited the same fileResolve conflicts manually, then commit
Accidental merge to wrong branchWrong base selectedRevert the PR and recreate with correct base
Too many commitsLong commit historyUse “Squash and Merge” for a cleaner log

tip
  • Always pull the latest main branch before merging
  • Use descriptive PR titles for better project history
  • Use “Squash and Merge” for small, single-purpose PRs
  • Delete merged branches to reduce clutter

Summary

You’ve learned how to:

  • Review and merge pull requests on GitHub
  • Understand merge options (merge, squash, rebase)
  • Handle conflicts before merging
  • Clean up branches after merging

This marks the completion of your GitHub journey — from creating repositories to collaborating and merging code.


Need help or want to share your first merged PR?

Join the GitHub Discussions community — we’d love to see your progress and support you on your journey