Better Terminal Git Diffs

August 12, 2020 • 1 minute read • @mitchhanbergAnalytics

Normally, our terminal git diffs look like this.

 normal git diff {: .bg-transparent }

Let's improve our experience by adding syntax highlighting!

To accomplish this, we're going to replace the pager that git uses with a tool called delta. Add the following to ~/.gitconfig.

[core]
  pager = "delta"

Let's see what our git diffs look like now.

git diff using delta as the pager{: .bg-transparent}

This looks great, but I think we can do even better. Let's configure delta to use the same theme as our terminal. delta uses bat for syntax highlighting, so we can use any theme that bat can use.

Grab your theme (you'll have to find a TextMate/Sublime Text version of it), copy it into ~/.config/bat/themes, and add the following option to your pager configuration.

[core]
  pager = "delta --theme='Forest Night'"

Now, the highlighting blends seamlessly with the rest of my development experience.

git diff using delta as the pager{: .bg-transparent}

One last improvement you can make is to use the same diff colors that your theme uses. I copied them from the theme file and added the following options to my pager configuration.

[core]
  pager = "delta --plus-color=\"#333B2F\" --minus-color=\"#382F32\" --theme='Forest Night'"

git diff using delta as the pager{: .bg-transparent}

Okay, now that our diffs look good, we can finally get back to work 😄.


If you want to stay current with what I'm working on and articles I write, join my mailing list!

I seldom send emails, and I will never share your email address with anyone else.