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 Option | Description | When to Use |
|---|---|---|
| Merge Commit | Adds all commits from the feature branch into the base branch with a single merge commit | Default, keeps full history |
| Squash and Merge | Combines all commits from the branch into one clean commit | Best for small feature updates or fixes |
| Rebase and Merge | Rewrites the commit history, placing your commits on top of the base branch | For 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!
6. Delete the Branch (Optional but Recommended)
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
| Problem | Cause | Solution |
|---|---|---|
| Merge conflicts | Both branches edited the same file | Resolve conflicts manually, then commit |
| Accidental merge to wrong branch | Wrong base selected | Revert the PR and recreate with correct base |
| Too many commits | Long commit history | Use “Squash and Merge” for a cleaner log |
- Always pull the latest
mainbranch 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