Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active April 10, 2026 13:12
Show Gist options
  • Select an option

  • Save dgoguerra/8258007 to your computer and use it in GitHub Desktop.

Select an option

Save dgoguerra/8258007 to your computer and use it in GitHub Desktop.
Setup p4merge as difftool and mergetool on Windows

Setting up p4merge as diff and merge tool on Windows. Tried for Git version 1.8.4.msysgit.0.

Two alternatives are explained: using the command line, and directly editing the config file.

Setting up from the command line

Being the installation path "C:Program Files\Perforce\p4merge.exe", just run:

$ git config --global diff.tool p4merge
$ git config --global difftool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'
$ git config --global merge.tool p4merge
$ git config --global mergetool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'

Possible error if other approaches have been tried before

Apparently in earlier versions mergetool.p4merge.cmd needed to be provided instead of the path, but doesn't work anymore due to Git trying to support p4merge:

setting mergetool.p4merge.cmd will not work anymore since Git has started trying to support p4merge, see libexec/git-core/git-mergetool--lib. instead it directly uses mergetool.p4merge.path

If that option is already set (check if git config --global --get mergetool.p4merge.cmd prints a value), it needs to be removed:

$ git config --global --unset mergetool.p4merge.cmd

The same applies to difftool.p4merge.cmd.

Editing the global configuration file

Open ~/.gitconfig (git config --global --edit) and add or change:

[merge]
	tool = p4merge
[mergetool "p4merge"]
	path = C:\\Program Files\\Perforce\\p4merge.exe
[diff]
	tool = p4merge
[difftool "p4merge"]
	path = C:\\Program Files\\Perforce\\p4merge.exe

As before, if inside [mergetool "p4merge"] or [difftool "p4merge"] there is a cmd option, it needs to be removed so that Git doesn't try to execute it.

@zfkingth

zfkingth commented Jul 28, 2016

Copy link
Copy Markdown

very good

@shabiba

shabiba commented Mar 11, 2017

Copy link
Copy Markdown

cool

@netcore-jroger

Copy link
Copy Markdown

cool.

@molanyon

molanyon commented Sep 7, 2017

Copy link
Copy Markdown

doesn't work

@ohadschn

ohadschn commented Nov 3, 2017

Copy link
Copy Markdown

The p4merge.path values should be double quoted - single quotes have no meaning in batch.

For example:
git config --global mergetool.p4merge.path "C:\Program Files\Perforce\p4merge.exe"

@MartyMacGyver

Copy link
Copy Markdown

@ohadschn The quotes appear to get removed by git config anyway. My global .gitconfig looks as it should (as above) and p4merge works.

@dionnyprensa

Copy link
Copy Markdown

Excellent!

@stevesuh

Copy link
Copy Markdown

Thanks!

@Maria-Resnik

Copy link
Copy Markdown

Tried the fix recommended above, and still getting message. Did these steps with diff and it works fine, only problem is with merge

The merge tool p4merge is not available as 'C:\Program Files\Perforce'

@arnoldpistorius

Copy link
Copy Markdown

Thank you

@YoussefZaghlol

Copy link
Copy Markdown

you are awesome, love you

@CrisSantos91

Copy link
Copy Markdown

Thank you!

@RPG3D

RPG3D commented May 11, 2020

Copy link
Copy Markdown

COOL

@mborus

mborus commented Aug 18, 2020

Copy link
Copy Markdown

As some people have mentioned before, use double quotes like

git config --global difftool.p4merge.path "C:\Program Files\Perforce\p4merge.exe" 

or else it will not work.

Also, if you don't have p4merge installed, it's here https://www.perforce.com/downloads/visual-merge-tool

@andrevnl

Copy link
Copy Markdown

Thank you

@fengjianyun

Copy link
Copy Markdown

Works like a charm

@SayrePeterson

Copy link
Copy Markdown

It still works, thank you! My professor linked to some outdated directions and it took me forever to find this gist and fix it finally

@brianearlapp

Copy link
Copy Markdown

This works for the merge tool but not the diff tool for some reason.

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