Working with PhpStorm? → Check my Mastering PhpStorm video course

Resolving Git conflicts with the magic rerere command


Git is huge! You can learn something new about it every day. Did you know that there is a barely known command called rerere? Let's take a look and learn something new to deal with merge conflicts.

Rerere what

Last week I had the chance to attend the Laracon EU conference in Amsterdam. It was an amazing event and I learned a lot . Especially this one talk about advanced Git tricks by Lorna Jane was really great. That was when I first heard about this barely known command.

Rerere stands for "reuse recorded resolution". If this Git feature is turned on, it does two things. First it will record how you deal with conflicts. Secondly, if there is the exact same conflict, Git will resolve it for you. Just like that!

Rerere how

This feature can be activated by setting a git config setting:

git config --global rerere.enabled true

That's it. From now on Git will remember how you resolve conflicts. You can see that it works when you take a closer look at the Git output after a conflict has been resolved.

Recorded resolution for 'index.html'.
[master b847e0a] fix conflict

And when Git can use an already recorded solution, it will let you know like this:

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Resolved 'index.html' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.

Rerere where

So now that we know what this feature is about, let's think about where this could be useful. If you are working with a feature branch workflow in Git, you will have to merge branches a lot. As a result you ran into same conflicts again and again. This can get really annoying and this is why the rerere feature comes in very handy here.

Do you enjoy my posts?

Sign up for my newsletter to receive updates on my latest content.

You will receive monthly updates on my latest articles and products. I do care about the protection of your data. Read my Privacy Policy.