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
Using Git Rerere for Repeated Conflict Resolution
📖 Scenario: You are working on a project with a team using Git. Sometimes, when merging branches, you face the same conflicts repeatedly. This wastes time because you have to fix the same conflicts again and again.Git has a feature called rerere that helps remember how you resolved conflicts once and applies the same fix automatically next time.
🎯 Goal: Learn how to enable Git rerere, simulate a repeated conflict, resolve it once, and then see rerere apply the fix automatically on the next conflict.
📋 What You'll Learn
Enable Git rerere in your repository
Create two branches with conflicting changes
Merge branches and resolve the conflict manually the first time
Merge again and observe rerere applying the conflict resolution automatically
💡 Why This Matters
🌍 Real World
Developers often face the same merge conflicts repeatedly when working on long-lived branches or feature branches. Git rerere helps automate conflict resolution, saving time and reducing errors.
💼 Career
Knowing how to use Git rerere is valuable for software developers, DevOps engineers, and anyone working with Git in collaborative projects to improve merge workflows.
Progress0 / 4 steps
1
Enable Git rerere in your repository
Run the command git config rerere.enabled true to enable rerere in your current Git repository.
Git
Hint
Use git config rerere.enabled true to turn on rerere.
2
Create two branches with conflicting changes
Create a file named file.txt with content Line 1 on the main branch. Then create a branch called branch1 and change file.txt to have Line 1 modified in branch1. Commit this change. Next, create another branch called branch2 from main and change file.txt to have Line 1 modified in branch2. Commit this change.
Git
Hint
Create the file and commit on main. Then create branches and commit different changes to cause a conflict.
3
Merge branches and resolve the conflict manually the first time
Checkout branch1 and merge branch2 into it using git merge branch2. When a conflict occurs in file.txt, open the file and replace the conflict markers with the line Line 1 resolved manually. Then add the file and commit the merge with message Resolve conflict manually.
Git
Hint
Merge branch2 into branch1, fix the conflict by replacing the file content, then commit.
4
Merge again and observe rerere applying the conflict resolution automatically
We are currently on branch1 after the first merge. Reset it to before the merge using git reset --hard HEAD~1. Then merge branch2 again using git merge branch2. This time, rerere should automatically apply the previous conflict resolution. Run git status to confirm the file is staged with no conflicts and then commit the merge with message Merge branch2 with rerere. Finally, print the contents of file.txt using cat file.txt to verify it shows Line 1 resolved manually.
Git
Hint
Reset the current branch to before the merge, merge branch2 again and see rerere apply the fix automatically. Check the file content.
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
Step 1: Understand what rerere stands for
Rerere means "reuse recorded resolution" and helps with repeated conflicts.
Step 2: Identify its function in Git
It saves conflict resolutions and applies them automatically if the same conflict happens again.
Final Answer:
It remembers how you resolved conflicts before and reuses those resolutions. -> Option B
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
Step 1: Recall the correct config syntax for rerere
The correct key is "rerere.enabled" with a dot, not "rerere.enable".
Step 2: Confirm the global flag placement
The global flag comes immediately after "config" and before the key-value pair.
Final Answer:
git config --global rerere.enabled true -> Option A
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
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.
Step 2: Analyze the second merge scenario
The second merge has the same conflicts, so rerere applies the previous resolution, avoiding manual conflict fixing.
Final Answer:
No conflicts, because rerere applied previous resolutions automatically. -> Option A
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
Step 1: Understand how rerere records resolutions
Rerere saves conflict resolutions only after you commit the resolved merge.
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.
Final Answer:
You forgot to commit the conflict resolution the first time. -> Option C
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
Step 1: Enable rerere globally for all repositories
This ensures rerere is active and can record conflict resolutions anywhere.
Step 2: Resolve the conflict once and commit the fix
Rerere records this resolution to reuse it automatically on repeated conflicts.
Step 3: Benefit from rerere auto-applying fixes on future merges
This saves time by avoiding repeated manual conflict resolution.
Final Answer:
Enable rerere globally, resolve the conflict once and commit, then rerere will auto-apply fixes on future merges. -> Option D