Bird
Raised Fist0
Gitdevops~15 mins

Rerere for repeated conflict resolution in Git - Deep Dive

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Overview - Rerere for repeated conflict resolution
What is it?
Rerere stands for 'reuse recorded resolution'. It is a feature in Git that helps automatically resolve repeated merge conflicts by remembering how you fixed them before. When you face the same conflict again, Git can apply your previous fix automatically. This saves time and reduces repetitive manual work during merges.
Why it matters
Without rerere, developers must manually fix the same conflicts every time they appear, which wastes time and increases the chance of mistakes. Rerere makes repeated conflict resolution faster and more reliable, improving productivity and reducing frustration in collaborative projects. It helps teams merge code smoothly even when conflicts happen often.
Where it fits
Before learning rerere, you should understand basic Git concepts like branching, merging, and conflict resolution. After mastering rerere, you can explore advanced Git workflows, automation with hooks, and continuous integration pipelines that benefit from automated conflict handling.
Mental Model
Core Idea
Rerere remembers how you fixed a conflict once and reuses that fix automatically when the same conflict happens again.
Think of it like...
Imagine you have a puzzle piece that keeps getting stuck in the same wrong spot. The first time you fix it, you remember exactly how you adjusted it. Next time you try the puzzle, you instantly place that piece correctly without struggling again.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│  Conflict     │──────▶│  Record Fix   │──────▶│  Reuse Fix    │
│  Happens      │       │  (rerere saves)│       │  Automatically│
└───────────────┘       └───────────────┘       └───────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding Git merge conflicts
🤔
Concept: Learn what causes merge conflicts and how Git signals them.
When two branches change the same part of a file differently, Git cannot merge automatically. It stops and marks the conflict in the file with special markers (<<<<<<<, =======, >>>>>>>). You must manually edit the file to fix the conflict.
Result
You see conflict markers in files and Git pauses the merge until you fix them.
Understanding conflicts is essential because rerere only helps after you know how to fix conflicts manually.
2
FoundationManual conflict resolution process
🤔
Concept: Learn how to fix conflicts step-by-step without automation.
Open the conflicted file, find the conflict markers, decide which changes to keep or combine, remove the markers, then stage the file with 'git add'. Finally, complete the merge with 'git commit'.
Result
The conflict is resolved and the merge finishes successfully.
Knowing manual resolution is the baseline so you can appreciate how rerere automates repeated fixes.
3
IntermediateEnabling rerere in Git
🤔
Concept: Learn how to turn on rerere to start recording conflict resolutions.
Run the command: git config --global rerere.enabled true This tells Git to track how you resolve conflicts and save that information for reuse.
Result
Git starts recording your conflict resolutions automatically.
Activating rerere is simple but crucial; without enabling it, Git won't remember your fixes.
4
IntermediateHow rerere records and reuses fixes
🤔Before reading on: do you think rerere fixes conflicts automatically on the first conflict or only on repeated conflicts? Commit to your answer.
Concept: Rerere saves your manual fix the first time, then applies it automatically on the next identical conflict.
When you fix a conflict and stage the file, rerere saves the conflict state and your resolution in a hidden directory. Next time the same conflict appears, rerere detects it and applies your saved fix automatically, so you don't have to edit the file again.
Result
Repeated conflicts are resolved automatically, speeding up merges.
Knowing rerere only automates repeated conflicts prevents confusion about when it helps.
5
IntermediateUsing rerere status and manual control
🤔
Concept: Learn how to check rerere's saved resolutions and manually apply them if needed.
Use 'git rerere status' to see conflicts rerere knows about. Use 'git rerere diff' to view saved resolutions. You can also run 'git rerere' manually to apply fixes if Git doesn't do it automatically.
Result
You gain control and insight into rerere's workings.
Understanding rerere's commands helps troubleshoot and manage complex merges.
6
AdvancedRerere with rebases and cherry-picks
🤔Before reading on: do you think rerere works only with merges or also with rebases and cherry-picks? Commit to your answer.
Concept: Rerere can help resolve repeated conflicts during rebases and cherry-picks, not just merges.
When you rebase or cherry-pick commits that cause conflicts you've fixed before, rerere applies your saved resolutions automatically, reducing manual work in these operations too.
Result
Conflict resolution is faster across multiple Git operations.
Knowing rerere works beyond merges expands its usefulness in daily Git workflows.
7
ExpertManaging rerere data and edge cases
🤔Before reading on: do you think rerere data is shared automatically across clones or must be managed manually? Commit to your answer.
Concept: Rerere data is stored locally and must be managed carefully to avoid stale or conflicting resolutions.
Rerere stores data in .git/rr-cache. This data is not shared by default between clones or team members. You can export/import rerere data manually if needed. Also, rerere may fail if conflicts change slightly, requiring manual fixes again.
Result
You understand rerere's limits and how to maintain its data.
Knowing rerere's local scope and data management prevents confusion and merge errors in teams.
Under the Hood
Git rerere works by hashing the conflicted file's conflict regions and storing the conflict state and your resolution in a cache directory (.git/rr-cache). When a new conflict occurs, Git hashes the conflict regions again and compares with stored hashes. If a match is found, Git applies the saved resolution automatically by replacing the conflicted region with the resolved content.
Why designed this way?
Rerere was designed to automate repetitive manual conflict fixes without changing Git's core merge logic. Storing conflict states as hashes allows efficient matching without storing entire files. Keeping data local avoids complexity and respects user control. Alternatives like fully automatic merges were too risky or complex.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Conflict      │──────▶│ Hash Conflict │──────▶│ Check Cache   │
│ Detected      │       │ Regions       │       │ (.git/rr-cache)│
└───────────────┘       └───────────────┘       └───────────────┘
        │                                               │
        │                                               ▼
        │                                    ┌───────────────────┐
        │                                    │ Match Found?      │
        │                                    ├─────────┬─────────┤
        │                                    │ Yes     │ No      │
        ▼                                    ▼         ▼         ▼
┌───────────────┐                   ┌───────────────┐  ┌───────────────┐
│ User Resolves │                   │ Apply Saved   │  │ User Resolves │
│ Conflict      │                   │ Resolution    │  │ Manually      │
└───────────────┘                   └───────────────┘  └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does rerere fix conflicts automatically the very first time you see them? Commit to yes or no.
Common Belief:Rerere automatically fixes conflicts the first time they appear without manual intervention.
Tap to reveal reality
Reality:Rerere only records your manual fix the first time and applies it automatically on repeated conflicts.
Why it matters:Expecting automatic fixes on first conflicts leads to confusion and wasted time waiting for rerere to act.
Quick: Is rerere data shared automatically between team members? Commit to yes or no.
Common Belief:Rerere data is shared automatically across all clones of a repository.
Tap to reveal reality
Reality:Rerere data is stored locally and not shared unless explicitly exported and imported.
Why it matters:Assuming shared data causes surprise when teammates still face conflicts you resolved.
Quick: Does rerere guarantee perfect conflict resolution every time? Commit to yes or no.
Common Belief:Rerere always resolves conflicts perfectly once it has recorded a fix.
Tap to reveal reality
Reality:Rerere works only if conflicts are identical; small changes in conflict regions can prevent automatic resolution.
Why it matters:Overreliance on rerere can cause missed conflicts or incorrect merges if conflicts evolve.
Quick: Can rerere fix conflicts during rebase and cherry-pick operations? Commit to yes or no.
Common Belief:Rerere only works during merge operations.
Tap to reveal reality
Reality:Rerere also works during rebases and cherry-picks to reuse recorded resolutions.
Why it matters:Not knowing this limits rerere's usefulness and causes unnecessary manual conflict fixes.
Expert Zone
1
Rerere's matching is based on hashing conflict hunks, so even small whitespace or context changes can prevent reuse, requiring manual intervention.
2
The rerere cache can grow large over time; cleaning or pruning it is necessary to avoid clutter and stale resolutions.
3
Sharing rerere data between team members requires manual export/import, which can be automated with scripts but is not built-in.
When NOT to use
Avoid relying on rerere when conflicts are highly dynamic or when you want full manual control over every merge. In such cases, manual conflict resolution or advanced merge tools like 'git mergetool' are better. Also, rerere is less useful in one-off merges where conflicts won't repeat.
Production Patterns
Teams enable rerere globally to speed up frequent merges in long-lived branches. Some use scripts to export rerere data to share fixes across developers. Rerere is integrated into automated CI pipelines to reduce manual conflict resolution during rebases or merges before deployment.
Connections
Cache mechanisms in computer systems
Rerere uses a cache-like system to store and reuse conflict resolutions.
Understanding caching principles helps grasp how rerere efficiently matches and applies previous fixes without redoing work.
Machine learning memoization
Both rerere and memoization store previous results to avoid repeated work.
Recognizing rerere as a form of memoization clarifies its role in optimizing repeated conflict resolution.
Human memory and habit formation
Rerere mimics how humans remember solutions to repeated problems and apply them automatically.
Seeing rerere as a digital habit-forming tool highlights its value in reducing cognitive load during repetitive tasks.
Common Pitfalls
#1Not enabling rerere before conflicts occur.
Wrong approach:git merge feature-branch # Fix conflicts manually but rerere is not enabled, so no recording happens.
Correct approach:git config --global rerere.enabled true git merge feature-branch # Fix conflicts manually; rerere records the fix for future reuse.
Root cause:Learners assume rerere works without enabling it, missing the configuration step.
#2Assuming rerere data is shared automatically between clones.
Wrong approach:Developer A fixes conflict with rerere enabled. Developer B pulls but rerere does not apply fixes automatically.
Correct approach:Developer A exports rerere data with 'git rerere export'. Developer B imports it with 'git rerere import' to share resolutions.
Root cause:Misunderstanding that rerere data is local and not part of the repository.
#3Expecting rerere to fix conflicts that have changed slightly.
Wrong approach:Rerere applies old fix to a conflict with different context, causing incorrect merges.
Correct approach:Manually resolve changed conflicts and stage them to update rerere cache with new resolution.
Root cause:Not realizing rerere matches exact conflict hunks and cannot adapt to changes.
Key Takeaways
Git rerere automates repeated conflict resolution by remembering your manual fixes and reapplying them when the same conflicts occur again.
You must enable rerere explicitly; it does not work by default and only records fixes after you enable it.
Rerere works across merges, rebases, and cherry-picks, making it broadly useful in many Git workflows.
Rerere data is stored locally and not shared automatically, so teams must manage sharing manually if desired.
Understanding rerere's limits and data management helps avoid merge errors and maximizes productivity in collaborative projects.

Practice

(1/5)
1. What is the main purpose of git rerere in conflict resolution?
easy
A. It creates a backup of your repository before merging.
B. It remembers how you resolved conflicts before and reuses those resolutions.
C. It deletes conflicting files after a merge.
D. It automatically merges branches without any conflicts.

Solution

  1. Step 1: Understand what rerere stands for

    Rerere means "reuse recorded resolution" and helps with repeated conflicts.
  2. Step 2: Identify its function in Git

    It saves conflict resolutions and applies them automatically if the same conflict happens again.
  3. Final Answer:

    It remembers how you resolved conflicts before and reuses those resolutions. -> Option B
  4. Quick Check:

    Rerere = reuse recorded resolution [OK]
Hint: Rerere reuses your past conflict fixes automatically [OK]
Common Mistakes:
  • Thinking rerere merges without conflicts
  • Believing rerere deletes files
  • Assuming rerere backs up the repo
2. Which command correctly enables rerere globally in Git?
easy
A. git config --global rerere.enabled true
B. git config --global rerere.enable true
C. git rerere enable --global
D. git config rerere.enabled true --global

Solution

  1. Step 1: Recall the correct config syntax for rerere

    The correct key is "rerere.enabled" with a dot, not "rerere.enable".
  2. Step 2: Confirm the global flag placement

    The global flag comes immediately after "config" and before the key-value pair.
  3. Final Answer:

    git config --global rerere.enabled true -> Option A
  4. Quick Check:

    Correct syntax uses rerere.enabled with --global [OK]
Hint: Use 'rerere.enabled' with --global to enable rerere [OK]
Common Mistakes:
  • Using rerere.enable instead of rerere.enabled
  • Placing --global after the key-value pair
  • Using 'git rerere enable' command which doesn't exist
3. Given this sequence of commands, what will git status show after the second merge if rerere is enabled?
git config --global rerere.enabled true
git checkout feature
# merge master with conflicts
# resolve conflicts manually and commit

git checkout feature
# merge master again with same conflicts
medium
A. No conflicts, because rerere applied previous resolutions automatically.
B. Conflicts remain and must be resolved again manually.
C. Merge fails with an error about unresolved conflicts.
D. Git deletes the conflicting files automatically.

Solution

  1. Step 1: Understand rerere behavior on repeated conflicts

    When rerere is enabled, it remembers how you fixed conflicts and applies those fixes automatically on the same conflict.
  2. Step 2: Analyze the second merge scenario

    The second merge has the same conflicts, so rerere applies the previous resolution, avoiding manual conflict fixing.
  3. Final Answer:

    No conflicts, because rerere applied previous resolutions automatically. -> Option A
  4. Quick Check:

    Rerere auto-applies fixes on repeated conflicts [OK]
Hint: Rerere auto-fixes repeated conflicts after first manual fix [OK]
Common Mistakes:
  • Expecting conflicts again despite rerere
  • Thinking merge will fail with error
  • Assuming files get deleted automatically
4. You enabled rerere but notice it does not apply previous conflict resolutions automatically. What is a likely cause?
medium
A. You enabled rerere only locally, not globally.
B. You used git rerere clear before the second merge.
C. You forgot to commit the conflict resolution the first time.
D. You merged branches with no conflicts.

Solution

  1. Step 1: Understand how rerere records resolutions

    Rerere saves conflict resolutions only after you commit the resolved merge.
  2. Step 2: Identify why rerere might not apply fixes

    If you did not commit the resolution, rerere has no record to reuse, so it cannot auto-apply fixes.
  3. Final Answer:

    You forgot to commit the conflict resolution the first time. -> Option C
  4. Quick Check:

    Rerere needs committed resolutions to reuse [OK]
Hint: Commit conflict fixes first for rerere to remember them [OK]
Common Mistakes:
  • Assuming rerere works without committing resolutions
  • Confusing rerere clearing with enabling
  • Thinking local vs global enable affects this issue
5. You have a project where the same conflict happens often between two branches. How can you use rerere to save time and avoid repeated manual fixes? Choose the best approach.
hard
A. Run git rerere clear before every merge to reset conflict history.
B. Disable rerere and always resolve conflicts manually to avoid mistakes.
C. Use rerere only on one branch and manually copy resolutions to the other branch.
D. Enable rerere globally, resolve the conflict once and commit, then rerere will auto-apply fixes on future merges.

Solution

  1. Step 1: Enable rerere globally for all repositories

    This ensures rerere is active and can record conflict resolutions anywhere.
  2. Step 2: Resolve the conflict once and commit the fix

    Rerere records this resolution to reuse it automatically on repeated conflicts.
  3. Step 3: Benefit from rerere auto-applying fixes on future merges

    This saves time by avoiding repeated manual conflict resolution.
  4. Final Answer:

    Enable rerere globally, resolve the conflict once and commit, then rerere will auto-apply fixes on future merges. -> Option D
  5. Quick Check:

    Enable + commit fix = rerere auto-applies [OK]
Hint: Enable rerere, commit fix once, future merges auto-fix [OK]
Common Mistakes:
  • Disabling rerere loses automation benefits
  • Using rerere only on one branch misses conflicts
  • Clearing rerere history removes saved fixes