Merge
In one line
Merging combines the changes from one branch into another, uniting two lines of development.
In simple words
Merging brings the commits from one branch into another. When your feature is finished, you switch to main and run git merge feature/login to fold the feature's changes into the main line. Git tries to combine the histories automatically.
If both branches changed the same lines, Git cannot decide which version wins and reports a merge conflict. You must open the conflicted files, choose the correct version, and commit the resolution. Good communication and small, frequent merges reduce conflicts.
An alternative to merging is rebasing, which replays your commits on top of the target branch for a linear history. Merging preserves the branch structure with a merge commit; rebasing rewrites history. Both are valid — choose based on your team's convention.
Example
# Switch to the target branch
git checkout main
# Merge the feature branch into main
git merge feature/login
# If there are conflicts, Git pauses:
# 1. Open the conflicted files and resolve them
# 2. Stage the resolved files
git add .
# 3. Complete the merge
git commitgit merge combines the feature branch into main. If conflicts occur, resolve them, stage, and commit.
Common confusions
Confused with: rebase
The difference: A merge combines two branches and creates a merge commit, preserving branch history. A rebase replays your commits on top of another branch, producing a linear history but rewriting commit hashes. Merge is safer for shared branches; rebase gives cleaner history.
Related terms
Related Resources
Related Lessons
- GitHub Basics
Merging via pull requests on GitHub
Learn the fundamentals
Deepen your understanding with structured lessons on this topic.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.