The most basic task any developer has when working with Git on a daily basis is adding files to be committed.
Probably the vast majority of us use git add -A without knowing exactly what is going on behind the scenes when we use the -A flag, and whether there are no other options that suit our needs better.
This command stages:
It is equivalent to git add --all.
This command stages:
This command stages
It is equivalent to git add --update.
If you want to stage a single file, run the git add command, specifying the path to the file:
git add src/components/Button/Button.tsx
If you want to stage all files inside a specific folder, specify the path to that folder:
git add src/components/
If you want to stage all files with a specific extension, for example .txt, run the following command:
git add -A *.txt
If you want to stage all files excluding deleted, run the following command:
git add --ignore-removal .
In this article, we have learned the main differences between the following commands: git add -A, git add . and git add -u.
You may never need to know the difference if you do not want to, as it is quite easy to restore an incorrectly deployed file using the git restore --staged command.