How to Install and Configure diff-so-fancy in Linux for Human-Readable Git Diffs

Reviewing code changes using standard git diff is a daily routine for software developers. However, the default Git output format dates back to the earliest days of Unix patch utilities. Cryptic @@ -12,7 +12,8 @@ chunk headers, repetitive + and - character prefixes on every line, and whole-line highlighting make identifying subtle word or punctuation modifications visually straining. diff-so-fancy is an open-source command-line tool that transforms standard Git diffs into clean, human-readable visual representations directly in your terminal.

Rather than cluttering your view with raw patch metadata, diff-so-fancy strips unnecessary leading plus and minus symbols, highlights exact word-level alterations within modified lines, formats file headers into distinct coloured banners, and aligns hunk markers cleanly. In this guide, you will learn how to install diff-so-fancy on Linux, integrate it with your global Git configuration, customise colour palettes, and optimize your code review workflow.

Why Use diff-so-fancy Over Default Git Diffs?

diff-so-fancy is specifically engineered to improve code review speed and reduce cognitive fatigue:

  • Granular Character-Level Highlighting: Instead of highlighting an entire replacement line in solid green, it applies bold accent colours to the exact words or characters that changed.
  • Clean Line Removal: Strips leading + and - symbols so you can copy and paste code directly from terminal diff output without manually deleting prefix characters.
  • Clear File Demarcation: Replaces messy diff --git a/file b/file text with prominent, colour-coded filename headers and divider rules.
  • Seamless Git Pager Integration: Works as a drop-in output filter for standard less, preserving standard terminal scrolling and search hotkeys.

Step 1: Install diff-so-fancy on Linux

diff-so-fancy can be installed via package managers, direct download, or npm. Choose the method appropriate for your distribution.

Installing via Direct Script Download (Universal Method)

Because diff-so-fancy is a standalone executable script with no heavy compiled dependencies, you can download it directly into your local binary directory:

sudo curl -sL https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy -o /usr/local/bin/diff-so-fancy
sudo chmod +x /usr/local/bin/diff-so-fancy

Installing on Arch Linux and Manjaro

On Arch-based distributions, install the package from the official community repository or AUR:

sudo pacman -S diff-so-fancy

Installing via npm (Node.js Environment)

If you already have Node.js and npm installed on your system:

npm install -g diff-so-fancy

Verify that the utility is installed and accessible in your shell PATH:

diff-so-fancy --version

Step 2: Configure Git to Use diff-so-fancy as Default Pager

To have Git automatically format all diffs, configure Git’s core.pager and colour options globally:

git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git config --global interactive.diffFilter "diff-so-fancy --patch"

Here is what the less flags achieve:

  • --tabs=4: Sets consistent 4-space tab stops for indented code blocks.
  • -R: Correctly interprets ANSI colour escape codes.
  • -F: Automatically exits the pager if the entire diff output fits on a single terminal screen.
  • -X: Prevents clearing the terminal screen buffer when less exits, preserving your diff view in scrollback history.

Step 3: Customise Git Colour Profiles for Optimal Contrast

To fully experience diff-so-fancy‘s refined aesthetic, configure Git’s diff colour palette to match its recommended visual scheme:

git config --global color.ui true

git config --global color.diff-highlight.oldNormal    "red bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.newNormal    "green bold"
git config --global color.diff-highlight.newHighlight "green bold 22"

git config --global color.diff.meta       "11"
git config --global color.diff.frag       "magenta bold"
git config --global color.diff.func       "146 bold"
git config --global color.diff.commit     "yellow bold"
git config --global color.diff.old        "red bold"
git config --global color.diff.new        "green bold"
git config --global color.diff.whitespace "red reverse"

Step 4: Test and Compare the New Diff Layout

Make a small edit to a tracked file in any Git repository and test the new output:

git diff

Notice the transformation:

  • A solid horizontal bar outlines the modified filename clearly.
  • Old code appears in soft red without leading minus signs.
  • New code appears in soft green without leading plus signs.
  • Specific word additions or variable renames within existing lines are highlighted with darker background contrast blocks.

You can also use diff-so-fancy with other Git commands:

git show
git log -p -2
git diff --staged

Step 5: Configure Custom Key Preferences and Options

diff-so-fancy includes several optional formatting preferences that you can configure via Git config keys:

Marking Empty Line Changes

To visibly highlight empty line additions or deletions that might otherwise look like phantom whitespace changes:

git config --bool --global diff-so-fancy.markEmptyLines true

Stripping Leading and Trailing Whitespace Indicators

If you prefer clean indentations without distracting whitespace symbols:

git config --bool --global diff-so-fancy.changeHunkIndicators true
git config --bool --global diff-so-fancy.stripLeadingSymbols true

Temporarily Bypassing diff-so-fancy

If you ever need raw standard patch output (for instance, when generating a patch file to send via email):

git --no-pager diff > changes.patch

This bypasses diff-so-fancy and generates standard, unformatted unified diff text compatible with git apply.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.