Using IDEA for Git merging and diffing

A cool bit of CLI trickery that James Humphrey shared with me. This allows you to use IDEA for diffing and merging via git’s mergetool and difftool commands.

First, add IDEA to your path (everything is in Mac-speak here):


export INTELLIJ_HOME /Applications/IntelliJ IDEA


set INTELLIJ_HOME /Applications/IntelliJ IDEA

Next, add these lines to your ~/.gitconfig file:

   tool = intellij
[mergetool "intellij"]
   cmd = idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
   trustExitCode = true
   tool = intellij
[difftool "intellij"]
   cmd = idea diff $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")

That’s it. Now you can use IDEA to diff and merge from git CLI like this:

$ git mergetool
$ git difftool

9 thoughts on “Using IDEA for Git merging and diffing

  1. If you’re having trouble getting this to work in MacOS/Linux (in particular, if invoking git diff/merge fails to bring up the IDEA diff/merge window), please note that JetBrains recommends creating a command-line launcher (Tools | Create Command-line Launcher) instead of putting the idea binary on your PATH directly:

    See also:


  2. This doesn’t work if idea is opened already. As command exits instantly, and files got deleted after that, Idea has not files to compare.


  3. If there are multiple files which need to be merged when you run git mergetool it seems like only the first file gets opened properly in IntelliJ. After that I get errors about unable to find LOCAL file.


    1. That’s strange. I wonder what Git is sending as parameters. That’s probably either an IJ bug of not handling multiple files passed in, or a git issue where it isn’t spawning the sub-process multiple times correctly. I’ll have to play around with it and see what is going on. Let me know if you figure it out.


  4. i’ve solved git configuration to use IntelliJ as merge tool like this in he .gitconfig file :

    [mergetool “intellij”]
    cmd = \”C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2022.1/bin/idea64.exe\” merge \”$LOCAL\” \”$REMOTE\” \”$BASE\” \”$MERGED\”
    trustExitCode = true
    [difftool “intellij”]
    cmd = \”C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2022.1/bin/idea64.exe\” diff \”$LOCAL\” \”$REMOTE\”

    i wrote my answer here :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s