Coding/Learn/git/git merge conflicts and rerere
Git & GitHub Complete Course
01.Introduction, Architecture & Configuration
02.Staging Area, atomic Commits & git status
03.Branching, Fast-Forward & 3-Way Merging
04.Stash, Log Visualization & History Inspection
05.Workflows (Git Flow, Trunk-Based) & Semantic Tagging
06.SSH Keys, Remote Repositories & Origin Setup
07.Push, Fetch, Pull & Upstream Tracking Branches
08.Forking, Clones & Open-Source Pull Requests (PRs)
09.GitHub Flow, Branch Protection & GitHub Pages
10.Undoing Changes: git restore & Safe Public git revert
11.Reset: Deep Dive into --soft, --mixed & --hard
12.Commit Amending & Interactive Rebase (git rebase -i)
13.Reflog & Disaster Recovery (Reviving "Lost" Commits)
14.Merge Conflicts Resolution & git rerere
15..gitignore Rules & .gitattributes Cross-Platform Handling
16.Hooks & Automated Quality Assurance (Pre-Commit)
17.Submodules & Large File Storage (Git LFS)
18.GPG Cryptographic Signing & git cherry-pick
19.Advanced Remotes, Garbage Collection (git gc) & Maintenance
20.Capstone: Production Multi-Branch Enterprise Release Pipeline
Course Certificate0%

Complete all lessons to earn

LearnMerge Conflicts Resolution & git rerere
14 / 20 0%
Lesson 14 of 20
6 mins read

Merge Conflicts Resolution & git rerere

PreviousNext Lesson
In Plain English

A merge conflict occurs when two branches modify the exact same lines of code in divergent ways. Git inserts conflict markers (<<<<<<< HEAD, =======, >>>>>>> branch) into the file. Developers resolve the conflict manually, stage the resolved file, and commit. git rerere (Reuse Recorded Resolution) remembers your resolutions automatically.

The Mental Model

"A merge conflict is two co-authors editing paragraph 3 of the same chapter differently: Git highlights both suggestions and asks the lead editor to decide on the final combined sentence."

Deep Dive: How It Works

Conflict Markers: <<<<<<< HEAD (current branch) vs >>>>>>> branch (incoming branch) separated by =======.

Resolution Steps: 1. Edit file to remove markers and keep desired code, 2. git add <file>, 3. git commit.

git rerere: Automatically applies previously recorded conflict resolutions during repeated rebases/merges.

Syntax Blueprint

git config --global rerere.enabled true
git merge feature
# Edit conflict in file.c
git add file.c
git commit -m "merge: resolve feature conflict"

Enable rerere auto-resolution memory, inspect conflict markers, edit, stage, and commit.

PointCore Rules to Remember

Point star
Three-Way Diff: Git compares Base Ancestor, Current HEAD, and Incoming Branch to detect collisions.
Point star
Conflict Markers: Always delete all <<<<<<<, =======, and >>>>>>> lines before staging.
Point star
rerere Memory: Saves countless hours during long-running rebase trains by remembering how you resolved conflicts.

Common Beginner Traps & How to Fix Them

Mistake:Accidentally leaving <<<<<<< HEAD markers in source files and committing them.

Why it happens: Rushing conflict resolution without testing code compilation.

How to fix: Always build and test project before completing the merge commit.

Pro Tip: Use git checkout --ours <file> or git checkout --theirs <file> to resolve binary or wholesale file conflicts quickly.

Live Interactive Example

Hit Run Code to see it live
Conflict Resolution Simulation
Git 2.45 / CLI
1
2
3
4
5
6
Output Console
Click "Run Code" to view the rendered output.
How it works: Staging the resolved file and committing completes the merge process.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Stage and Commit Conflict Resolution

  • PointWrite "PORT=8080" to server.env to resolve the conflict.
  • PointStage server.env with "git add server.env".
  • PointCommit with message "merge: resolve port conflict".
1
2
3
4
5
6
7
8
9
10
11
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates