# 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"


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.yulrizka.com/git/git-mergetool-and-diff-with-p4merge.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
