DEV Community

Cover image for Don't use "git add ."
Jeferson 'Shin' Leite Borges
Jeferson 'Shin' Leite Borges

Posted on • Updated on

Don't use "git add ."

TL:DR

git add -A will stages all changes
git add . will stages new files and modifications, without deletions
git add -u stages modifications and deletions, without new files


Wait, this post is in English. So keep going!

I never put enough thought into the mentor I had. He was not the teacher, he was a guide in this world of web development, just pointing my focus and attention to learning the right thing. And I remember when he told me to avoid using git add . and instead use git add -A.

At that time, I never thought about it, I just assumed I was doing it wrong, until yesterday I was wondering why there are two ways to add files to the stage area.

When you add files with git add ., you are adding every single file in the current folder, or structure, or anything like that, It's ok, you can do that, you can even add git add file.js for example.

But if you want to add any deletion, update and all changes in the other directories, in this case, you should use add git add -A, this -A means ALL.

Another way is to update only the updated files, without any test file, or some experimental code, in this case, you can use git add -u, this -u means UPDATE.

Easy to remember, right?

(()=>{})()

Top comments (4)

Collapse
 
thomasspare profile image
Spare

Must try this. So if I use git add -A the IDE saves every directory/ file as it is. Is this the case even if I have not saved an edited file ?

Collapse
 
shinspiegel profile image
Jeferson 'Shin' Leite Borges

Depends on the implementation of the IDE,
If you file isn't "saved", there is nothing that git can do to fix it.
In this case save all your files and use the git add -A, all the files in tracked by the .git folder will be saved, not only the current folder.

Collapse
 
theluk profile image
Lukas Klinzing

git add -i

Collapse
 
shinspiegel profile image
Jeferson 'Shin' Leite Borges

I did read about it, but I didn't tried this. I'm curious about the "interactive mode" of these.