The git mergetool
command allows you to resolve merge conflicts from your command line. Many merge tools are available like vimdiff
, which helps you resolve the conflicts without leaving your terminal. But of course, there are also merge tools available that open in a separate window to resolve the conflicts, like opendiff
, meld
, kdiff3
, and many more. You can run git mergetool --tool-help
to see which ones are available to you.
For Java devs, IntelliJ-IDEA's 3-way merge tool provides much more comfort compared to these other merge tools. One reason is syntax highlighting, but it also seems to understand the conflicts. Often it can merge the changes automatically. Yet, I've always found it a hassle to move between my terminal and IDE.
Today, all that changed when I discovered that it's possible to merge files from the command line. So, after reading the git manual in some more detail, I added the following to my git config (i.e. git config --global --edit
):
[merge]
tool = idea
[mergetool "idea"]
cmd = idea merge $LOCAL $REMOTE $BASE $MERGED
trustExitCode = false
Now, when I run into conflicts, I type git mergetool
and IntelliJ-IDEA opens a 3-way merge window. 🚀
Not on macOS?
The config above works for macOS, on another OS you need to adjust the configuration using the OS-specifics from the merge files from the command line documentation.What are those
*.orig
files?
The merge tool creates some*.orig
files that stay around after resolving the conflicts. These are backup files that can be safely removed after a successful merge, or used to undo your conflict resolution. You can control these backup files withmergetool.keepBackup
.
I don't regularly blog, and I'm not a native English speaker. But, I hope you found this post useful. Please reach out, if you have any tips on how I could improve. Of course, I'd also love to hear about it if you liked my post.
Thanks for reading ❤️
Top comments (0)