Imagine you’re an integrator (someone who takes a lot of changes from other people and merges them) and you often merge other people’s branches, resolve conflicts, and then find bugs in the branch. Wouldn’t it be great if git could remember your conflict resolutions and replay them next time you try to merge? That’s what git rerere is for!

To enable git rerere for all your git repos, use git config --global rerere.enabled 1. This will make a change in your ~/.gitconfig.

After you’ve done that, git rerere just basically works. Any time you have merge conflicts, it will automatically record the original and resolved states and replay them next time you try to merge. Any merge, rebase, or am action will use git rerere.

If you have a long-lived topic branch that you know will conflict when merged with another branch (say, master), you can do a git pull origin master, fix conflicts and commit, and then git reset --hard HEAD^. This way you can get the benefit of merging often without the history cluttering of many “useless merges”.

References:

About these ads