Skip to content

Instantly share code, notes, and snippets.

@idefav
Forked from ffittschen/gitconfig.md
Created July 14, 2023 02:13
Show Gist options
  • Select an option

  • Save idefav/2bd1ed7683e127549b7df4e73b929bf6 to your computer and use it in GitHub Desktop.

Select an option

Save idefav/2bd1ed7683e127549b7df4e73b929bf6 to your computer and use it in GitHub Desktop.
Use IntelliJ or WebStorm as git mergetool with SourceTree

Use IntelliJ or WebStorm as git mergetool

Configure Sourcetree

The merge tool that ships with JetBrain's IntelliJ IDEA or WebStorm is really awesome and way better than FileMerge. It is quite simple to configure SourceTree to use it as the default mergetool:

  1. Open the SourceTree preferences and select the Diff tab

  2. Choose Custom both as Visual Diff Tool and as Merge Tool

  3. Paste the following commands into the textfields:

    • Diff Command: /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea diff

      • Arguments: $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")
    • Merge Command: /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea merge

      • Arguments: $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
  4. Close the settings. Happy merging!

Git in general

To manually change the mergetool for git in general follow these steps:

  1. Open the ~/.gitconfig file with your favorite editor

  2. Add these lines somewhere in the config:

    [merge]
            tool = intellij
    [difftool "intellij"]
            cmd = /Applications/IntelliJ\\ IDEA.app/Contents/MacOS/idea diff $(cd $(dirname \"$LOCAL\") && pwd)/$(basename \"$LOCAL\") $(cd $(dirname \"$REMOTE\") && pwd)/$(basename \"$REMOTE\")
    [mergetool "intellij"]
            cmd = /Applications/IntelliJ\\ IDEA.app/Contents/MacOS/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
    

Downsides

It takes a few more seconds to launch the IntelliJ merge tool than to launch FileMerge, but it is definitely worth waiting.

Credits

Based on this article on coderwall: https://coderwall.com/p/gc_hqw/use-intellij-or-webstorm-as-your-git-diff-tool-even-on-windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment