Skip to content
Tech News
← Back to articles

Using Git's rerere feature to escape recurring conflict hell

read original get Git Rerere Memory Tool → more articles
Why This Matters

The git rerere feature offers a powerful solution to recurring merge conflicts, saving developers time and reducing frustration during complex version control workflows. Its ability to automatically reuse previous conflict resolutions streamlines collaboration and enhances productivity for both individual developers and teams.

Key Takeaways

Have you ever tried to merge two branches only to end up in conflict hell? You fix a bunch of conflicts only to run git merge --continue and be presented with the same conflicts. Repeat this process and after a few iterations you give up because it just isn't worth the pain and effort.

Would you be surprised to know that there is a git feature specifically for this problem? It's called rerere and I'm going to enrich your life with it now. (I'm going to talk specifically about merging but I think it also helps rebasing)

rerere stands for Reuse Recorded Resolution. The TL;DR version is you ask git to remember how you've resolved hunks in the past, and if the same one comes up for a file in future just redo what you did last time.

To enable this feature just run this lovely command git config --global rerere.enabled true . You can also turn it on by creating this directory in your projects .git/rr-cache , although the global setting is much clearer.

I'll try to take you through an example of how this works, bear with me it might get long.

We have our (tiny) project with only one file in it, which looks like this

. └── user.rb 0 directories, 1 file

I branch off master to create a branch called dev and I add a line to user.rb . Now I would like to stage this change so I pull down staging and try to merge my dev branch but uh oh, someone has merged a change to staging affecting the same line in user.rb that I am editing.

/tmp/example [staging] » git merge dev Auto-merging user.rb CONFLICT (content): Merge conflict in user.rb Automatic merge failed; fix conflicts and then commit the result.

We've all seen this before, a run of the mill conflict message. However if you were to have rerere enabled you would get this output

... continue reading