Resolve Git Merge Conflicts With Magic (well, not really magic)


Hi friends,

Today we’re going to explore a lesser-known but incredibly powerful feature of Git: git rerere.

This feature is particularly useful for anyone who frequently manages branches and encounters merge conflicts.

What is git rerere?

The git rerere feature stands for “reuse recorded resolution.” It helps to automate the resolution of merge conflicts by remembering how you’ve resolved them in the past. When enabled, git rerere kicks in as soon as a conflict occurs and before you’ve started resolving it. If it recognizes a conflict that you’ve resolved before, it will automatically apply the same resolution, saving you the effort of manually resolving the same conflict repeatedly.

Before you can start taking advantage of rerere, you need to enable it in your Git configuration:

git config --global rerere.enabled true

This command activates git rerere across all your Git repositories. Alternatively, you can enable it only in a specific repository by running the command without the --global flag inside that repository.

How git rerere Benefits Rebasing

Rebasing is a common but sometimes tricky part of working with Git, especially when working on long-lived branches or in teams. Conflicts are inevitable. git rerere shines in these scenarios by remembering how conflicts were resolved during previous rebases.

This memory allows it to automatically resolve recurring conflicts that arise from applying old patches onto a newer base. This automation can reduce the complexity and time involved in resolving conflicts during a rebase.

Under The Hood

git rerere stores the resolutions in a unique way.
When a conflict is first resolved, it saves the pre-conflict and post-conflict versions of the files involved, along with a description of the conflict itself. These are stored in three separate files:

  • Preimage (pre): This file stores the state of the content just before the conflict occurred.
  • Postimage (post): This file records the state of the content after the conflict has been resolved.
  • Status: This file contains metadata about the conflict, including the unique identifiers of the conflict states.

These files are stored under the .git/rr-cache directory.

The next time git encounters an already recorded conflict of a "preimage", I'll use the recording from "postimage" to handle it.

git rerere is a robust tool that can make handling complex rebase operations much simpler. By learning to leverage it, you can significantly improve your workflow efficiency, particularly in collaborative environments where rebases and conflicts are common.

A word of caution though: `rerere` can be sometimes dangerous, and may resolve conflict in ways you didn't necessarily anticipate, in which case deleting a recording that isn't 100% relevant may be needed.
However, as long as the commit tree is kept clean, with small, traceable changes, the conflicts will also be small and easy to fix.


Thanks for reading! As always, feel free to respond to this email with feedback / suggestions / mistakes.

Happy weekend!

Whenever you’re ready, here’s how I can help you:

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

Give me 10 minutes and I'll make you a REGEX expert. This issue is brought to you by: Warp is a fully fledged Agentic Development Environment. From prompt → production “The IDE is dead. The ADE is in”.Coding tasks start with a prompt in Warp, not a heavyweight IDE that takes up 3/4 of your screen with code. Warp is free to try but for a limited time, try Warp Pro free for 7 days with 2,500 Al credits-no card required. Click here to start (It’s Free!) Regex has been around for years -...

You’ve been parsing JSON wrong your whole life This issue is brought to you by: Secure Your AI Future at DevSecCon 2025 Software development is undergoing a seismic shift as AI transforms how we build, deploy, and secure applications. Register for the 1st-ever Global Community Summit on AI Security, covering critical strategies to empower AI innovation without compromising security. Register for DevSecCon 2025 (It’s Free!) Ever opened a massive “.log” file and realized it’s just one long,...

Wait… cURL can do WHAT?! Brought to you in collaboration with 1Password and Browserbase: 🔐 Your AI Agents Can Finally Log In! 1Password and Browserbase just partnered to solve AI’s biggest security nightmare: authentication without exposing credentials. Introducing 1Password’s Secure Agentic Autofill, allowing you to connect your 1Password Enterprise Password Manager to your browser automation agent powered by Browserbase. Build AI agents that can actually work without compromising security....