In this post I wish to document the correct and concise difference between these 4 types of git command to add files to stage them for a commit to your online repository.
1. git add . v/s git add *
add * adds all the files in the current directory, and stages them for a commit, except the ones that begin with a dot. Files beginning with a . are hidden for add *n.
On the other hand, git add . will add all the files, folders, sub-folders to the staging area along with the ones that begin with a ‘.’ .
I also read that * is not a part of git. It is a wildcard, interpreted by the shell. * expands to all the files in the current directory. However, add . refers to the current directory itself and git add . will add all the files in that directory, including the files beginning with a dot.
NOTE: Both add * and add . don’t add the removed files for commiting.
2. git add * v/s git add -A/–all v/s git add -u
This table depicts graphically the difference between these 3 implements of git add.
add . or add * indexes all the new and modified files and stages them for a commit, except for the files that have been removed.
add -u stages all modified and removed files for a commit, except for the new files created. It does not add any new files, it only stages changes to the files that have been tracked before.
add -A or add –all is a combination of both add . & add -u. It will add all new files, modified files and removed files, for staging.
Hope I have been able to make the difference between these 4 kinds of add commands clear.