Fast and simple tip to increase your Git Fu level.

TL;DR, run the following code in your terminal and be happy:

git config --global rerere.enabled 1

Explaining: Git rerere (reuse recorded resolution) is a hidden Git feature which, as the name says, allow record and reuse previous conflicts resolutions.

Let's say you are working in a feature-a branch, created from master branch. Some time later, you discover your colleague made some changes in master that can lead to a conflict with your feature-a code.

So, to make sure your new feature will still work when are ready, you go to the new master branch and try to merge your feature-a branch. As expected, you got some conflicts between the two branchs. So you solve them right now, as your new code is still fresh in your mind, and conclude the merge.

I don't always have merge conflicts, but when I do, I have no idea how to solve
Sometimes is not so easy.

But there's a problem, the feature-a isn't ready, so you can't push it to master now. So, after doing your tests, you discard the merge you just have made and go back to work on feature-a.

Generally, this means you are discarding your conflicts resolutions too, then later, when you are ready to merge feature-a definitively, you'll must solve the conflicts again. That's when enters Git rerere.

Git rerere records the changes you made to resolve a given conflict and can reapply it later, when you get the same conflict again. To use it, you must run the command git rerere every time you finish resolving a conflict, before doing the resolved merge commit (it works with rebase too!).

But you can make you life easy. With the command from the first lines of the article you enable Git rerere to run automatically every time you resolve some conflict during a merge. The resolution will be saved and, when you got the same conflict again, it'll be applied automatically, so you just need to review it and make the final commit if everything is ok.

Git rerere is a feature to enable and forget it's exists, it'll be ready to do its job just when you need it.

Leave a comment

Interesting feature, but I don't think I understand why I wouldn't rebase feature-a on master instead?

Then I could get a permanent conflict solution right away, and there's no need to solve the same conflict again?

Rebase rewrites history, so sometimes you can't do it (for example, if another user is working on the same branch, his branch will break when you rebase it).

Also rerere can be useful in another situations where you can need to resolve the same conflict several times.

You may also want to set git config --global rerere.autoupdate true so that your index is also updated (default is false.)

If you need to surpress rerere for a particular merge operation, you can do this since 1.7 using --no-rerere-autoupdate

And all your recorded resolutions are stored in .git/rr-cache, so you can share this directory with other devs who may need them.

Thanks Forest, great tips!