git add . was a command I used all the time until I started working as a software engineer. Now, that command feels like a hammer.

"If all you have is a hammer, everything looks like a nail."

This expression describes situations where one might rely too heavily on a familiar tool or approach, even when it's not appropriate.

I had heard there were other approaches to staging changes with git. However, working alone, learning to code, I never found myself in a situation to use anything other than git add .

However, since working in situation where I needed to submit a pull request for code review, it has felt like a poor fit. I’ll explain why.

Why git add . is a hammer?

The simple answer is that it doesn’t feel precise enough. I want to know the specific files and changes that I’m saving in my git history.

Let me explain some situations I’ve come across recently.

  1. Sometimes I open a file, change nothing, then save and close it. At times Prettier has reformatted that file before I save it. Git recognizes tracks these changes and git add . will stage them.

  2. Ever added a quick console.log to check something but forgot to delete it? Well git is tracking that change and git add . will stage that change.