Is it possible to configure the temp file folder in git diff?

Same Problem, solution not by changing temp directory of git but using the diff script you can define:

  1. Define script for diff in .gitconfig

    [diff]
    external = /home/user/scripts/my_diff.sh
    
  2. Create script /home/user/scripts/my_diff.sh to use the Windows tool:

    #!/bin/bash
    FILE2="C:\\dev\\wsl\\Debian\\rootfs\\${2//\//\\}"
    FILE1=$(wslpath -w $5)
    /c/Program\ Files\ \(x86\)/WinMerge/WinMergeU.exe $FILE1 $FILE2
    

In my example I am using WinMerge.
I know that this solution is against the rule that Windows tools are not allowed to touch Linux files, but I am fine with that since we are talking about a temp file and I don't see the point of changing it in WinMerge anyhow. The manual path substitution is necessary because wslpath does not work on Linux internal path.

Your WSL might be different, normally somewhere

C:\Users\%username%\AppData\Local\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState\rootfs

This feels a little hacky, but I am using it and am happy up till now.


You can try setting the TMPDIR environment variable.

From the POSIX manual:

TMPDIR This variable shall represent a pathname of a directory made available for programs that need a place to create temporary files.


After a quick look at the git code (git/builtin/difftool.c), I don't think configuring the temp directory is currently supported:

/* Setup temp directories */
tmp = getenv("TMPDIR");
xsnprintf(tmpdir, sizeof(tmpdir), "%s/git-difftool.XXXXXX", tmp ? tmp : "/tmp");

Seems like git is taking the TMPDIR value, or "/tmp", if TMPDIR is not defined.