Git Tricks with Tri and Difft
26 March 2026
Updated: 04 May 2026
Assumed audience: Developers/technical people who use git and/or enjoy terminal UIs (TUIs)
So I finally got tri running super fast which I already talked about today and I came across something mildly annoying but not all bad so thought it would be nice to write down
I use difft for my git diffs. This works really nicely as it’s got some syntax awareness and integrates really well into other tools I use such as lazygit
Now, I’m a Unix Philosophy dude so I build my tools to do the same - so naturally I wanted to use difft with tri - so, here’s how to do that
The below examples are using Nushell so your shell’s exact syntax may vary but the idea is the same
1git diff HEAD --name-only | GIT_EXTERNAL_DIFF="difft --color=always --display=inline" tri --preview `git diff HEAD -- `Okay, braindump definitely. Realistically, since I want difft to always behave like this, It’s probably worth setting the environment variable elsewhere, but the steps are basically:
- Use the
GIT_EXTERNAL_DIFFenvironment variable to have thedifftcommand, this causes git to use the entire command and not just execute the binary provided as withdiff.external, so I can provide the flags to formatdifftas desired - Then just use
trias normal
Assuming you’ve set step 1. within your shell, the command is more simply:
1# step 1.2$env.GIT_EXTERNAL_DIFF = "difft --color=always --display=inline"3
4#step 2.5git diff HEAD --name-only | tri --preview `git diff HEAD -- `Which is just the normal way that tri works so yay
And that’s it okbye
Update 14 April 2026
I’ve added this function to my nu config which basically do the above:
1def "g diff tri" [range = "HEAD..master"] {2 git diff ($range) --name-only3 | GIT_EXTERNAL_DIFF="difft --color=always --display=inline" tri --preview $"git diff ($range) -- " --flat4}Update 04 May 2026
I’ve wanted to do more complex preview behavior with tri - particularly making it possible to generate custom commands. I’ve recently added support for that so it now makes for some really interesting stuff, like a command for example the below command which lets you browse the input files’ history
Using it looks like this:
1^find **/*.go | g log triAnd the definition is a bit messy, but not too complicated I hope:
1# Expects a list of paths as an input2def "g log tri" [] {3 $in4 | lines5 | par-each {|p| git log --pretty=format:"%h %as %f" -- $p | str replace -m -a --regex ^ $"($p)/" }6 | to text7 | GIT_EXTERNAL_DIFF="difft --color=always --display=inline" tri --preview "git diff $2 -- $1" --pattern `^(.*)/(\w+)`8}This is also probably very inefficient. So be selective about the paths you provide since this does a log for all given paths and can be very slow on a large repository