Published at
Updated at
Reading time
1min

I recently saw an interesting tip from Paul Irish on Twitter. He shared that he uses git diff not only for reviewing git changes but also for general file diffing. If you use the --no-index argument, you can compare any files. These files can be outside of git repositories, too.

This discovery is beautiful because I recently spent quite a bit of time tweaking my git diff command using delta. And I love it when things look consistent in my terminal.

A new default diff command

I added a new diff command to my zsh setup. It overwrites the default diff command and uses git diff --no-index instead. In only does that, though, if there are exactly two command arguments. Otherwise falls back to the default diff behavior.

function diff() {
  if [ "$#" -ne 2 ]; then
    command diff "$@"
    return
  fi

  git diff --no-index $1 $2;
}

See below how my new diff fileA fileB command looks like now!

git diff command showing a diff of two files in two columns

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly — Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles