DEV Community

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

Posted on

1 1

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay