How to Merge Branches in GitHub (Step by Step Guide)
Merging branches in GitHub helps you combine code changes from different development lines into one. If you are new to GitHub, this guide will show you clear steps to merge branches safely and effectively.
Table of contents
How to Merge a Branch in GitHub?
1. Merge Using GitHub Website
You can easily merge branches from the GitHub interface.
- Open your repository on GitHub.
- Click the Pull requests tab at the top.
- Select New pull request.
- Choose the base branch (usually main) and compare it with your feature branch.
- Review the changes and click Create pull request.

- Add a title and description, then click Merge pull request.

- Confirm by clicking Confirm merge.
Before creating a pull request, many developers also start by cloning the repository in GitHub to work locally.
Need only part of a repo for review or testing? Learn how to download a folder from GitHub to grab specific files without cloning the whole project.
2. Merge Using Git Commands
If you prefer the terminal, follow these steps:
- Open Git Bash or your terminal.
- Run:
git checkout main
git pull origin main
git merge feature-branch
git push origin main
Replace feature-branch with the name of the branch you want to merge.
After completing a merge, you may want to clean up by deleting a branch in GitHub that you no longer need.
3. Handle Merge Conflicts
Conflicts occur when two branches change the same lines of code.
- Git will highlight the conflicting files.
- Open the file and decide which changes to keep.
- After editing, run:
git add .
git commit
git push origin main
This completes the conflict resolution and finishes the merge. For a detailed walkthrough of spotting conflict markers and fixing them in Git or the GitHub editor, read how to resolve conflicts in GitHub.
Why Merging Matters
Merging ensures that all team members work on the latest code. It helps maintain a single source of truth and reduces the risk of duplicate or outdated work.
FAQs
Open GitHub Desktop, switch to the base branch, then click Branch > Merge into Current Branch and select your feature branch.
Yes, you can use git reset or revert the merge commit if you want to undo the changes.
Merge keeps the history of both branches while rebase creates a linear history by applying commits on top of the main branch.
Yes, in shared repositories you need write or maintainer access to merge branches into the main branch.
Conclusion
Merging branches in GitHub is a core skill for collaborative development. Whether you use the web interface or command line, following these steps will keep your projects organized, updated, and conflict-free. To boost your workflow even further, you can also use GitHub Copilot in Visual Studio for AI-powered coding assistance.
For even better project organization, see this guide on how to create a folder in GitHub.
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
User forum
0 messages