Select git mergetool based on file type

git, git-config, gitattributes, merge

Solution

One solution (since my old answer isn't a good fit for `mergetool`) is to set as a `mergetool` a wrapper script.

git config --global merge.tool customMergeTool
git config --global mergetool.customMergeTool.cmd 'customMergeTool.sh \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'

That wrapper script `customMergeTool.sh` would:

- check what `$BASE` is (in particular, its file extension)

- call the appropriate merge tool based on that extension

- return the exit status of that `mergetool`

Here is for instance the script that the OP elsevers came up with: `merge-wrapper`.

Problem

When running `git mergetool`, I'd like to have git select the merge tool used based on the file extension. How can I do this? A similar question was asked here: Git: configure patterns for difftool and mergetool and the answer was to write a custom merge driver. However, it seems like this would be executed upon `git merge`, whereas I would like the merge tool to be chosen upon `git mergetool`. It seems like there must be some way to specify this with .gitattributes, but I can't seem to figure out how. Any advice?

Original source

Related problems