Git merging & conflicts
This course covers how Git combines branches and what to do when it cannot do so automatically. It explains fast-forward and three-way merges, and how conflicts arise when both sides change the same lines. It shows how to read and resolve conflict markers, including the zdiff3 style. It also shows how to abort a merge and pick one side with git restore. Finally, it covers git rebase, its golden rule and interactive cleanup, ending with merging a feature branch into main.
What you'll learn
- ✓Fast-forward and three-way merges
- ✓Why conflicts happen and how to read conflict markers
- ✓Resolving conflicts by hand or taking one side with git restore
- ✓Aborting a merge or rebase and starting over
- ✓Rebasing a branch and when not to rebase
- ✓Cleaning up local commits with interactive rebase
Two ways to combine branches: fast-forward and three-way merge
The Branching course built one line of history off main and left it there on purpose. add-discount-percentage sits two commits ahead, untouched by main. A branch that never rejoins isn't finished work: it's an experiment nobody acted on. git merge is how it comes home.
Read the full lesson free →Curriculum
7 lessonsTwo ways to combine branches: fast-forward and three-way merge
Explains fast-forward merges, three-way merges with a merge commit, how to tell them apart, and --no-ff.
When Git can't merge automatically: conflicts
Shows how a conflict happens when both sides change the same lines, and what git status reports.
Reading and resolving conflict markers
Covers reading conflict markers, editing to a final version, staging the file, committing, and the zdiff3 style.
Aborting and retrying a merge
Shows git merge --abort, choosing one side with git restore --ours or --theirs, git mergetool, and merging main often.
The other way to combine: git rebase
Explains how git rebase replays commits onto another branch, how to handle its conflicts, and when to choose it.
The golden rule of rebase, and interactive cleanup
Covers the rule against rebasing pushed commits and using git rebase -i to reword, squash, fixup or drop commits.
Putting it all together: merge the feature branch back into main
Walks through checking, updating, merging, verifying and deleting a feature branch locally and on the remote.