How to customize git diff to spot changes faster

Srebalaji Thirumalai
Level Up Coding
Published in
2 min readAug 20, 2020

--

git diff is one of the most useful features in git. Customizing diff will make your life easier.

Diff-so-fancy is the git tool that helps you to make good looking diffs. This tool helps you to spot the differences without any human error.

You can view the package in this repo

Let’s see that in-depth

Installation

Diff-so-fancy is available in brew, npm and also as a package for Debian Linux

brew install diff-so-fancy npm i diff-so-fancy --global

Usage

I will explain a few ways of using diff-so-fancy. You can choose your way of doing it.

Be default, diff-so-fancy will never change any default diff options. You should explicitly mention it.

git diff | diff-so-fancy

The above command will use diff-so-fancy to display the difference.

If you want to make diff-so-fancy as default diff viewer, you can use

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

Now you can just use git diff to use diff-so-fancy.

Now for some reason, you may wish to use the default git diff to view the change even after setting diff-so-fancy.

In that case, you can use

git --no-pager diff

The above command will bypass diff-so-fancy. So the default diff view will be used.

Remove diff-so-fancy from the default option

To remove diff-so-fancy from the default git diff, you can set the pager as

git config --global core.pager 'less'

Git uses a pager to display the content. Pager is used in commands like git-diff, git-log. By default, a pager called less is used by Git.

So in the above command, I have set the default pager to Git.

diff-so-fancy comes with few options. You can see that in the repo.

Thank you for reading, I hope you learned something new :)

If you have come this much, then I think you are much interested in Git. You can subscribe to my newsletter GitBetter to get tricks, tips, and advanced topics of Git.

--

--