0
0
Gitdevops~7 mins

Rerere for repeated conflict resolution in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you fix the same merge conflicts multiple times, it wastes time. Git's rerere feature remembers how you resolved conflicts before and applies the same fixes automatically, saving effort.
When you frequently merge branches that cause the same conflicts repeatedly.
When you rebase a branch multiple times and encounter the same conflicts.
When you collaborate on a feature branch that often needs syncing with the main branch.
When you want to speed up conflict resolution in long-running branches.
When you want to reduce human error by reusing previous conflict fixes.
Commands
This command turns on the rerere feature globally so Git will start remembering how you resolve conflicts.
Terminal
git config --global rerere.enabled true
Expected OutputExpected
No output (command runs silently)
Attempt to merge the feature-branch into your current branch. If conflicts appear, you will resolve them manually this first time.
Terminal
git merge feature-branch
Expected OutputExpected
Auto-merging file.txt CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result.
Check which files have conflicts that need manual resolution.
Terminal
git status
Expected OutputExpected
On branch main You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: file.txt
Open the conflicted file in a text editor to manually fix the conflict by choosing the correct code.
Terminal
nano file.txt
Expected OutputExpected
No output (command runs silently)
Mark the conflict as resolved by adding the fixed file to the staging area.
Terminal
git add file.txt
Expected OutputExpected
No output (command runs silently)
Commit the merge with the conflict resolved. Git rerere now remembers this resolution for future conflicts.
Terminal
git commit -m "Resolve conflict in file.txt"
Expected OutputExpected
[main 1a2b3c4] Resolve conflict in file.txt
-m - Provide a commit message inline
Next time you merge the same branch or similar conflicts appear, Git rerere will automatically apply the previous fix.
Terminal
git merge feature-branch
Expected OutputExpected
Auto-merging file.txt Merge made by the 'recursive' strategy.
Key Concept

If you remember nothing else from this pattern, remember: Git rerere saves your conflict fixes and reuses them automatically to speed up repeated merges.

Common Mistakes
Not enabling rerere before resolving conflicts
Git cannot remember conflict resolutions retroactively, so rerere won't help unless enabled first.
Always run 'git config --global rerere.enabled true' before starting merges where conflicts may occur.
Not committing after resolving conflicts the first time
Git rerere only records conflict resolutions after you commit, so skipping the commit means no record is saved.
After fixing conflicts, stage and commit the changes to save the resolution.
Ignoring rerere's automatic fixes and manually fixing again
Manually fixing conflicts repeatedly wastes time and defeats rerere's purpose.
Trust rerere to apply previous fixes and only intervene if the conflict is new or different.
Summary
Enable rerere globally with 'git config --global rerere.enabled true' to start recording conflict resolutions.
Manually resolve conflicts and commit the changes the first time they appear so rerere can save the fix.
On future merges with the same conflicts, rerere automatically applies your previous resolutions, speeding up merges.