0
0
Gitdevops~30 mins

Rerere for repeated conflict resolution in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Reset the current branch to before the merge, merge branch2 again and see rerere apply the fix automatically. Check the file content.