git rerere: stop re-resolving the same conflict after every agent rebase
TL;DR: git rerere (“reuse recorded resolution”) remembers how you resolved a conflict and replays it the next time the same conflict appears. Turn it on with git config rerere.enabled true — the manual is explicit that without that setting the command does nothing, and on Git 2.47.3 a fresh repository recorded nothing until it was set. Every resolved conflict is stored as a preimage/postimage pair under .git/rr-cache/<hash>/, and the next time the identical conflict comes back Git writes your old answer into the working tree and prints Resolved 'config.txt' using previous resolution. You still have to git add and commit, unless you also set rerere.autoUpdate true, which stages the replayed result for you.
What you’ll be able to do:
- Turn a repeated merge conflict into a one-line
git addinstead of a re-merge. - Inspect what Git recorded before you trust it (
git rerere status,git rerere diff, and the rawpreimage/postimagefiles). - Understand the one condition that decides whether a resolution is reused: the conflict text has to be identical.
- Drop a recorded resolution that turned out to be wrong (
git rerere forget <path>) instead of living with it forever.
Honest take: rerere replays text, not intent. It can hand you a merge that was right for the situation you resolved last week and is wrong for the one in front of you. Use it to remove mechanical work, then read the diff before you commit.
Why the same conflict keeps coming back
Long-lived topic branches are the classic case, and the git rerere manual opens with exactly that scenario: “In a workflow employing relatively long lived topic branches, the developer sometimes needs to resolve the same conflicts over and over again until the topic branches are done.”
An AI coding agent turns that scenario into the default. A typical loop looks like this:
- The agent opens a branch and edits
config.toml,docker-compose.yml, or a lockfile. - You merge main into the branch, or ask the agent to rebase onto the updated main. The agent’s edit and your edit land on the same lines.
- You resolve it by hand — picking the value that makes sense for both sides.
- The agent pushes another commit, you pull again, and the identical conflict returns.
Without help, step 4 is step 3 again, from memory, every time. With rerere, step 3 happens once.
What rerere actually stores
The manual’s one-paragraph description is precise: the command works “by recording conflicted automerge results and corresponding hand resolve results on the initial manual merge, and applying previously recorded hand resolutions to their corresponding automerge results.”
So two things are stored per conflict:
- preimage — the conflicted file exactly as Git wrote it out, with the
<<<<<<</=======/>>>>>>>markers. - postimage — the file after you resolved it.
The pair lives in .git/rr-cache/<sha1>/ — the rr-cache directory is the same one the git-config manual mentions when it notes that rerere is enabled by default if such a directory already exists in the repository. The directory name is a hash of the preimage, and that hash is the whole matching mechanism: if the conflicted text is byte-for-byte the same, Git finds the directory and replays the postimage.
I built a throwaway repository to capture the real output. The base commit had two settings, an agent branch raised one of them, and the main branch moved the other:
port = 8080
workers = 4
The first merge conflicted. With git config rerere.enabled true already set, the resolution was recorded and .git/rr-cache appeared:
$ git rerere status
config.txt
$ ls .git/rr-cache
2cbb3125c8f750be69a48e645044023fe6353db1
$ ls .git/rr-cache/2cbb3125c8f750be69a48e645044023fe6353db1/
postimage
preimage
The stored files are plain text, and readable:
$ cat .git/rr-cache/*/preimage
<<<<<<<
port = 8080
workers = 16
=======
port = 9090
workers = 4
>>>>>>>
$ cat .git/rr-cache/*/postimage
port = 9090
workers = 16
That preimage is the conflict as Git produced it: the <<<<<<< side is the branch being merged in (port = 8080, workers = 16), the ======= side is yours (port = 9090, workers = 4). The postimage is the resolution I wrote: main’s port, the agent’s worker count.
While you are still resolving, git rerere diff shows what has been recorded so far, and git rerere status lists the paths whose resolution rerere is about to store. In my run, git rerere diff printed the conflict as a patch:
--- a/config.txt
+++ b/config.txt
@@ -1,7 +1,2 @@
-<<<<<<<
-port = 8080
-workers = 16
-=======
port = 9090
-workers = 4
->>>>>>>
+workers = 16
Recorded resolution for 'config.txt'.
The replay
With that resolution stored, the same conflict a second time is resolved by Git instead of by you. The merge still reports a conflict — that is expected — but the file is already filled in with your earlier answer:
Auto-merging config.txt
CONFLICT (content): Merge conflict in config.txt
Resolved 'config.txt' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.
$ git status --short
UU config.txt
$ cat config.txt
port = 9090
workers = 16
Read the last two lines carefully, because this is where people get surprised. The file content is your old resolution, but the index still says UU — unmerged. The merge is not finished until you stage it:
$ git add config.txt
$ git commit -m "merge agent-a (rerere reused the recorded resolution)"
The git merge manual explains the flag that removes even that step. --rerere-autoupdate “allow[s] it to also update the index with the result of resolution”, and it recommends the opposite for review: --no-rerere-autoupdate “is a good way to double-check what git-rerere did and catch potential mismerges, before committing the result to the index with a separate git-add”. With rerere.autoUpdate true in the config, the same conflict came back and the index was already staged:
$ git status --short
M config.txt
$ cat config.txt
port = 9090
workers = 16
The difference between UU and M is the entire difference between “one command to fix it” and “read it, then fix it”.
The rule that decides whether a resolution is reused
The preimage must match exactly. Not “the same file”, not “the same lines” — the same conflicted text, down to the markers.
This is the failure mode worth internalising, because it looks like rerere is broken when it is actually working as designed. If the two sides of the conflict differ at all — a different merge base, one side renamed a line, a hunk grew a third line — the preimage is a different string, it hashes to a different directory name, and there is nothing to replay. Git then records a new preimage for the new shape.
In my fixture, the third merge of the same branch was structurally identical to the second and was replayed. A fourth merge, where the agent branch had also added a line, produced a conflict of a different shape — a partial hunk instead of the whole file:
<<<<<<< HEAD
port = 9090
workers = 4
=======
port = 8080
workers = 16
note = keep
>>>>>>> agent-c
The merge stayed unresolved (UU config.txt), and the cache grew a second directory with a different hash — f1bf521562002b0f2b9570725e3f858449ab17ac next to the original 2cbb3125c8f750be69a48e645044023fe6353db1 — holding a preimage with the new shape. Different text, different hash, no replay. If your agent keeps producing slightly different conflicts, rerere will look like it is doing nothing, and the reason is the conflict shape, not the setting.
The commands you will actually use
| Command | What it does | When you need it |
|---|---|---|
git rerere status | Lists paths whose resolution rerere will record | Right after a conflict, to confirm rerere noticed it |
git rerere diff | Shows the recorded-vs-current diff for the conflict in progress | While you are resolving, to see what has been stored |
git rerere remaining | Lists conflicts rerere could not auto-resolve | When the replay did not happen and you want to know why |
git rerere forget <path> | Drops the recorded resolution for a path | When the stored answer was wrong for this situation |
git rerere gc | Prunes old records | Housekeeping; unresolved records older than 15 days and resolved ones older than 60 days are pruned by default |
git rerere clear | Resets rerere’s working state | When you abort a merge or rebase; git merge --abort and git rebase --abort call it for you |
git rerere forget is the escape hatch, and it is the one to reach for first when a replay looks wrong. The recorded answer stays in the cache until you forget it or until gc prunes it, so one bad resolution can keep reappearing.
Turning it on for a machine that runs agents
If an agent runs merges or rebases on your behalf, the setting belongs in the repository or in your global config, not in a per-command flag:
git config --global rerere.enabled true
git config --global rerere.autoUpdate true
Or per repository, which is the better choice when you want the behaviour only where an agent works:
git config rerere.enabled true
git config rerere.autoUpdate true
Start with rerere.enabled true and leave rerere.autoUpdate off. You get the replay, you still read the result and stage it yourself, and you avoid a merged commit that nobody looked at. Turn autoupdate on only when the diff is already covered by something else — a test run, a reviewer, a CI gate.
The same reasoning applies to the other half of the problem. rerere removes the editing work; it does not remove the review work, and it does not remove the merge itself. If you need to know which commit introduced a bad change rather than which lines changed, git bisect run is the tool for that, and if you need to compare a rewritten series against what the agent claims it did, git range-diff answers a different question. Keep each tool on its own job: rerere replays, bisect localises, range-diff compares.
Two more practical notes from working with this in an agent workflow:
- Conflicts in submodules are never replayed.
git rerere remainingexplicitly lists paths “whose resolutions cannot be tracked by rerere, such as conflicting submodules”. - A merge you abort leaves rerere’s working state dirty. The manual notes that
git am --skip/--abortandgit rebase --skip/--abortinvokegit rerere clearautomatically; if you abort a merge by other means, rungit rerere clearyourself.
Honest take: what rerere will not do
- It does not merge semantically. The replay is a text substitution of the file you stored. If the surrounding code changed, the replayed file can be internally inconsistent with the rest of the tree.
- It does not tell you the resolution was right. It tells you that you made the same choice before. Only a test run does that.
- It keys on text, so it silently stops helping when the conflict shape drifts. If your agent’s edits change shape every time, you will get no replays and no error message.
- The cache grows with the number of distinct conflicts.
git rerere gcexists for that reason.
Use it for the boring, repeatable conflicts — config values, lockfile headers, import blocks that an agent keeps re-touching — and keep reading the diff. The tool removes the part where you re-type the same answer for the fourth time; it does not remove the part where you decide whether the answer is still correct.
Sources
- git-rerere manual: recording and replaying conflict resolutions,
clear/forget/diff/status/remaining/gc, and thererere.enabledrequirement — git-scm.com - git-config:
rerere.enabled,rerere.autoUpdate,gc.rerereUnresolvedandgc.rerereResolved— git-scm.com - git-merge:
--rerere-autoupdate/--no-rerere-autoupdateand the advice to review a replay before staging it — git-scm.com - git-rebase: how a rebase raises conflicts and how
--continue/--abortinteract with rerere — git-scm.com - git-worktree: keeping parallel agent tasks in separate working trees — git-scm.com
Last updated November 18, 2026. The behaviour above was checked against the current git-scm.com manual and reproduced locally with Git 2.47.3 in a throwaway repository. The output blocks are real fixture output, not illustrations. No hosted service, paid API, or model inference was involved.
Was this article helpful?
Thanks for the feedback — it helps improve future articles.
Need hands-on help?
I offer 1-on-1 technical consulting for local AI setup, GPU selection, and AI coding tool configuration — same topics covered on this site.
Book a session — $49 / hour →Know which coding tool is worth paying for
Hands-on comparisons of AI coding assistants and what each one costs to run — including the local-model path. Sent only when something changes. Unsubscribe anytime.