DEV Community

Cover image for How To Use `git diff`
Lucia Cerchie
Lucia Cerchie

Posted on

How To Use `git diff`

What do you do when your code was working on main but you've checked out a new branch, added a few changes, and it's failing?

One of your available tools is a powerful command my coworker taught me recently: git diff.

With it, you can see the differences between your current branch and main.

For example, say your Prettier settings are suddenly not working after switching to a new branch and playing around a bit. You run git diff, scroll through the changes, and see:

 {
-  "editor.formatOnSave": true
+  "editor.formatOnSave": false,
 }
Enter fullscreen mode Exit fullscreen mode

Oh my gosh! Somehow, your Prettier settings got set to false for formatOnSave. That explains it!

git diff can save you a lot of time when you're debugging code behavior that's different from that on main. Let me know what other git tools increase your coding productivity!

Top comments (1)

Collapse
 
waylonwalker profile image
Waylon Walker

Super useful skill, especially for comparing branches like you showed