skip to content

What does git rerere do, and when does it actually save you work?

level: seniorimportance: nice to knowfreq 28%

answer

  1. The name is an abbreviation of a whole phrase
  2. It only helps when something repeats
  3. Keyed by the conflict text, not the file name
  4. A cache inside .git, never pushed
  5. There is a command to make it forget

basics

~20 s

Git rerere records how you resolved a conflict and replays that resolution automatically the next time the identical conflict appears. It pays off when the same conflict recurs — repeated rebases of a long-lived branch, or an integration branch rebuilt from scratch.

solid answer

~50 s

Rerere stands for **reuse recorded resolution**. Turn it on with `git config --global rerere.enabled true`. From then on, whenever a merge or rebase conflicts, Git fingerprints the conflict hunks and — once you finish resolving — stores the before/after pair under `.git/rr-cache`. If it later meets a conflict with the same fingerprint, it applies the stored resolution to the working tree for you and tells you so; you still inspect and `git add` unless `rerere.autoUpdate` is set to stage it automatically. The win is entirely about *repetition*: rebasing a long-lived branch every day, re-creating an integration branch that merges several topics, or replaying a rebase you had to abort. It is local-only — the cache lives in your repository and is never pushed — and it will happily reapply a resolution that was wrong or has gone stale, which is why `git rerere forget <path>` exists.

go deeper

for a junior

Enough to know the feature exists and that it replays a resolution you already made. Nobody expects a junior to have configured it.

for a middle

Explain the record-and-replay mechanism, that it is keyed by conflict content and stored locally, and that a reused resolution still needs staging unless you opt into automatic staging.

for a senior

Name the concrete scenarios where it pays — repeated rebases of a long-lived branch, rebuilt integration branches — and the failure mode of silently reapplying a stale or wrong decision, plus how you would catch that.

for a principal

Treat it as a symptom manager: recurring identical conflicts are a signal about branch lifetime and file structure. Decide when to recommend it and when the right fix is to stop generating the conflict.

## The problem it solves Some conflicts you resolve once. Others you resolve again and again: a topic branch that lives for weeks and is rebased onto a moving trunk every morning; an integration branch that merges five topics and is thrown away and rebuilt nightly; a rebase you abort and restart after realising something else was wrong first. In all of these the *same* textual disagreement, between the same two versions, comes back. Resolving it identically by hand each time is pure repetition — and each repetition is an opportunity to resolve it differently by accident. ## What it records With `rerere.enabled` set to true, Git watches conflicts. At the moment a conflict appears it computes a normalised fingerprint of each conflicted hunk — essentially the pre-image, the two sides as presented. When you finish the resolution (by staging the file and completing the merge or rebase step), Git stores the resolved text against that fingerprint in `.git/rr-cache`. Each recorded resolution is keyed by the conflict content, not by file name, branch or commit, so the same conflict in a renamed file is still recognised. ## What it replays Later, when a merge or rebase produces a conflict whose fingerprint matches a stored one, Git writes the recorded resolution into the working tree instead of leaving the raw markers, and reports that it resolved the path using a previous resolution. Two important qualifications: - By default it stops there. The path is still unmerged in the index, so you review the result and `git add` it. Setting `rerere.autoUpdate` to true makes Git stage the reused resolution as well, which is convenient and correspondingly easier to sleepwalk through. - A partial match is possible: some hunks in a file may be auto-resolved while others still need you. ## The inspection commands `git rerere status` lists the paths for which a resolution is currently being tracked. `git rerere diff` shows what the recorded resolution changes relative to the conflicted state — the fastest way to answer "what exactly did it just do to my file?". `git rerere forget <path>` drops the recorded resolution for that path so the next occurrence conflicts normally again; this is your escape hatch when a resolution was wrong, or when the code around it has moved on and the old resolution no longer makes sense. ## The risks worth naming Rerere's failure mode is confidence. It reapplies a decision you made once, possibly weeks ago, possibly wrongly, without asking. If that decision dropped one side's change, every future occurrence silently drops it too. Because the cache is local and invisible in the diff, two engineers rebasing the same branch can end up with genuinely different results and no obvious explanation. The mitigations are ordinary engineering discipline: read what it did on the first reuse, keep tests running after every rebase step that reports a reuse, and forget resolutions that predate a significant refactor of the region. ## Scope and lifetime The cache is per-repository, stored inside `.git`, and is not transferred by push, fetch or clone — a fresh clone starts with no recorded resolutions. Entries have a limited lifetime and are pruned by garbage collection over time, with separate ages for resolved and unresolved records; the practical implication is that rerere helps with conflicts that recur *soon*, not with one that returns after six months. ## When to recommend it Recommend it to anyone maintaining a long-lived branch against a fast-moving trunk, anyone who rebuilds integration branches, and anyone who has aborted a painful rebase and dreads restarting. Do not present it as a general conflict-reduction strategy: it does not reduce the number of conflicts, only the number of times you decide the same thing. If the same conflict recurs daily for weeks, the deeper answer is usually to land the branch sooner or restructure the file, and rerere is the anaesthetic rather than the cure.

  • Does enabling rerere stage the reused resolution for you?
    Not by default. It writes the recorded resolution into the working tree and reports the reuse, but the path stays unmerged so you can inspect it and run `git add` yourself. Setting `rerere.autoUpdate` to true stages it automatically, which is faster and makes it easier to miss a resolution that has gone stale.
  • A recorded resolution is now wrong because the surrounding code was refactored. What do you do?
    Run `git rerere forget <path>` to drop the stored resolution for that path, then resolve the conflict by hand so a fresh, correct resolution is recorded. `git rerere diff` is useful first to confirm exactly what the stale resolution was doing before you discard it.
  • Can teammates share your recorded resolutions?
    No. The cache lives under `.git` in your own repository and is never transferred by push, fetch or clone. Two people rebasing the same branch can therefore reach different results with no visible cause, which is one reason to read what a reuse did rather than trusting it silently.

saying these in an interview costs you the question

  • Says it prevents conflicts from happening
  • Believes the resolution cache is pushed to the remote
  • Assumes it commits the resolution automatically by default
  • Trusts a replayed resolution without reading it
  • Cannot name a scenario where the same conflict recurs

context