How Git branches and merges work
An animated explainer of Git branching: branch pointers, fast-forward vs three-way merges, the common ancestor and merge conflicts.
Chapters
- Commits and branches: Each commit is a snapshot of your project, linked to its parent. main has commits A, B, C. git switch -c feature adds a new pointer at C.
- Diverging work: Commits D and E land on feature, moving its pointer forward, while main gets its own commit F. The two histories now split after C.
- Merging: git merge feature into main asks: fast-forward possible? Only if main has not moved. It has, so Git runs a three-way merge using the common ancestor C.
- Conflict and merge commit: Conflict? Both sides changed the tea price, so you edit the lines, git add, and commit. Without a conflict, Git creates merge commit M straight away.
Make an animated explainer of your own topic →