git add -A or git add –all :
What it does is it’s going to stage all the changes, all the modified, deleted, and new files, and the dot file in the entire working tree.
So, you can say it does the entire working tree it means that if you are in my subdirectory and you can execute git add -A
It will stage all the changes no matter what subdirectory you are in.
We can also use git add -A to stage all the changes in a particular directory.
git add -A
It is the default behavior of git add. so, I can leave off the -A then also it is going to do the exact same thing for all the above 3 cases. Now this behavior is actually new to git version 2. In git version 1 if you left off -A it would ignore the deleted files. Now, if you still want that git version 1 functionality just do git add –no-all or git add –ignore-removal .
git add -u or git add –update :
It add all the modified and deleted files but not any untracked files and it does this for the entire tree.
So, if you specify a directory then it would stage all the modified and deleted files in that subdirectory but will not stage any untracked files without affecting the changes in its parent directory.
git add .
This specific command will stage all the changes no matter what type it is whether it be untracked files or deleted files or modified files.
Now, it might seem like it does the exact same as git add -A but it looks the same as long as you are in the top directory. So let’s see how this is different. If you are in your top directory then git add -A and git add . are the exact same.
So, you can see in the above image doing git add . in the subdirectory will stage all changes in that subdirectory but will not affect its parent directory. So the main difference between git add . and git add -A is that in git add -A no matter from where you execute this command it will stage everything whether it be the subdirectory or the parent directory but git add . stages only the changes in the current directory and not it’s parent directory.
git add *
Now, you can see many students using this command and you can personally avoid this command and advice you the same, this is because * is a shell command and it’s not something that git specifically knows how to use it will just take everything that’s aster.
As shown below when you will execute the command git add * gives a very unexpected result because it couldn’t see the deleted files but one deleted file got added to the staging area and this deleted file didn’t and the hidden file didn’t get at it.