> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/git/git-mergetool-and-diff-with-p4merge.md).

# git mergetool and diff with p4merge

Some time you want visually merge conflict in git. To use p4merge <https://www.perforce.com/products/helix-core-apps/merge-diff-tool-p4merge>

## git mergetool

### Linux

```
$ git config --global merge.tool p4mergetool
$ git config --global mergetool.p4mergetool.cmd \
$ "/opt/p4v/bin/p4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
$ git config --global mergetool.p4mergetool.trustExitCode false
$ git config --global mergetool.keepBackup false
```

### Mac

```
$ git config --global merge.tool p4mergetool
$ git config --global mergetool.p4mergetool.cmd \
"/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
$ git config --global mergetool.p4mergetool.trustExitCode false
$ git config --global mergetool.keepBackup false
```

## Set as diff tool

### Linux

$ git config --global merge.tool p4mergetool $ git config --global mergetool.p4mergetool.cmd "/opt/p4v/bin/p4merge $LOCAL $REMOTE"

### Mac

$ git config --global diff.tool p4mergetool $ git config --global difftool.p4mergetool.cmd "/Applications/p4merge.app/Contents/Resources/launchp4merge $LOCAL $REMOTE"
