Git Rerere Explained: Resolve a Merge Conflict Only Once
Git rerere records how you resolve a merge conflict and replays that fix automatically when the same conflict reappears during rebases or merges.
Git rerere, short for “reuse recorded resolution”, is a built-in Git feature that remembers how you resolved a merge conflict and automatically applies the same resolution the next time Git encounters an identical conflict. If you have ever fixed the same conflicting hunk three times while rebasing a long-lived branch, rerere is the feature that makes the second and third time disappear.
It is off by default, takes one line to enable, and works quietly across merges, rebases, and cherry-picks.
The problem rerere solves
Some workflows produce the same conflict repeatedly:
- Repeated rebasing. You keep a feature branch current by rebasing it onto
mainevery few days. A conflict in one file has to be resolved again each time, because a rebase replays your commits from scratch. The trade-offs between the two strategies are covered in git rebase vs merge. - Test merges. You merge a topic branch into an integration branch to check that it works, then throw the merge away. When you do the real merge later, the same conflicts come back.
- Aborted operations. You get halfway through a tricky rebase, abort it to rethink, and start again.
- Backports. You cherry-pick the same fix onto several release branches that conflict in the same way.
In each case you are solving a problem you have already solved. Rerere stores the answer.
Step 1: enable rerere
Turn it on globally so it works in every repository:
git config --global rerere.enabled true
Optionally, let Git stage files it resolves automatically:
git config --global rerere.autoUpdate true
Without autoUpdate, rerere still rewrites the conflicted file with your old resolution, but leaves it unstaged so you can review it before running git add. Many people prefer that extra checkpoint, at least until they trust the feature.
Step 2: resolve a conflict as usual
With rerere enabled, nothing about your normal workflow changes. Start a merge that conflicts:
git merge feature/billing
Alongside the usual conflict message, Git prints a line such as:
Recorded preimage for 'src/invoice.ts'
The preimage is the conflicted state of the file, including the conflict markers. Rerere has fingerprinted the specific conflicting hunks.
Now resolve the conflict in your editor, stage the file, and commit:
git add src/invoice.ts
git commit
Git reports:
Recorded resolution for 'src/invoice.ts'.
That postimage, your resolved version of the hunks, is stored alongside the preimage in the repository’s .git/rr-cache directory.
Step 3: let rerere replay it
Suppose you undo that merge and redo it later, or the same conflict appears during a rebase. This time Git prints:
Resolved 'src/invoice.ts' using previous resolution.
The file already contains your earlier fix. If autoUpdate is off, review it and stage it. Then continue the merge or rebase as normal.
Rerere matches on the conflicting hunks themselves, not on commit IDs or branch names, so it recognises the conflict even when the surrounding history is completely different. It also normalises the order of the two sides, so a conflict that appears with “ours” and “theirs” swapped, which is common when switching between merging and rebasing, can still match.
Inspecting and correcting recorded resolutions
A few subcommands help you see what rerere is doing:
git rerere status # files with conflicts rerere is tracking right now
git rerere diff # how the current resolution differs from the preimage
If you recorded a bad resolution, tell rerere to forget it while the conflict is active:
git rerere forget src/invoice.ts
Then resolve the file correctly and commit. The new resolution replaces the old one.
If you want Git to re-create the conflict markers so you can examine the raw conflict instead of the replayed answer, check out the conflicted version of the file:
git checkout --conflict=merge src/invoice.ts
Housekeeping
Recorded resolutions accumulate. git gc prunes old ones automatically, and you can trigger the cleanup explicitly:
git rerere gc
The retention periods are configurable through gc.rerereResolved and gc.rerereUnresolved. Because the cache lives inside .git, it is local to your clone. It is not pushed or shared with teammates, and deleting the clone deletes it.
Rerere compared with other conflict tools
| Rerere | Manual resolution | Merge strategy options (-X ours / -X theirs) | |
|---|---|---|---|
| What it does | Replays your earlier fix for an identical conflict | You edit every conflict by hand | Picks one side automatically for all conflicting hunks |
| Uses your judgement | Yes, recorded once | Yes, every time | No |
| Safe for unfamiliar conflicts | Only applies to ones it has seen | Yes | Risky; silently discards changes |
| Persistence | Local .git/rr-cache | None | None |
| Best for | Repeated rebases, test merges, backports | One-off conflicts | Bulk cases where one side should always win |
Caveats
A replayed resolution is not a verified one. Rerere applies a textual fix. If the surrounding code has changed so that the old resolution no longer compiles or behaves correctly, rerere will not notice. Run your build and tests after any operation where rerere stepped in, and use git bisect if a regression slips through.
Mistakes repeat too. A wrong resolution will be faithfully replayed until you forget it.
Recovery still works. If a rebase goes badly, rerere does not change Git’s safety net. Git reflog still records where your branch pointed before the operation, so you can reset and try again, and rerere will remember the parts you got right.
The full list of subcommands and configuration options is in the official git rerere documentation.
The takeaway
Git rerere records the conflicted hunks and your resolution, then replays that resolution automatically whenever the same conflict reappears in a merge, rebase, or cherry-pick. Enable it with git config --global rerere.enabled true, keep autoUpdate off until you trust it, use git rerere forget to correct a bad recording, and always rebuild and test after rerere has resolved something for you.
Tagged
Keep reading
The Lycoris Team · · 4 min read What Is Git Reflog? Recovering Lost Commits
Git reflog records every place HEAD and branch tips have pointed, letting you recover commits that look lost after a reset, rebase, or deleted branch.
The Lycoris Team · · 5 min read What Are Conventional Commits? A Commit Convention
Conventional Commits structures commit messages as type(scope): description so tools can auto-generate changelogs and version bumps from git history.
The Lycoris Team · · 4 min read Git Stash Explained: Shelve Changes Without Committing
Git stash saves uncommitted work to a hidden stack so you can switch branches cleanly. How stash, pop, apply, and stash branches actually work.