Git Merging
What is Merging?
- Merging combines changes from one branch into another
- Usually done into
mainormaster
Types of Merge
| Merge Type | When It Happens | What Git Does | Merge Commit | Command |
|---|---|---|---|---|
| Fast-Forward Merge | Target branch has no new commits | Moves branch pointer forward | No | git merge feature-branch |
| Non Fast-Forward Merge | Both branches have new commits | Creates a merge commit, preserves history | Yes | git merge feature-branch |
Branch Merge Commands
Merge a branch
git merge bug-fix: Merge into the current branch
Abort merge
git merge --abort
Merge Conflict
- Occurs when Git cannot auto-merge changes
- Usually when same file, same line is modified
Steps to resolve:
- Open conflicted files
- Fix conflict markers (
<<<<<<<,=======,>>>>>>>) git add <file>git commit

Point to remember
- Use fast-forward for clean history
- Use non fast-forward to keep branch context