I'm new to git and I have a question about adding files in git. I have found multiple stackoverflow questions about the difference between git add .
and git add -a
, git add --all
, git add -A
, etc. But I've been unable to find a place that explains what git add *
does. I've even looked at the git add man page, but it didn't help. I've been using it in place of git add .
and my co-worker asked me why. I didn't have an answer. I've just always used git add *
.
Are git add .
and git add *
the same? Does one add changed files from the current directory only, while the other adds files from the current directory and subdirectories (recursively)?
There's a great chart listed on one of the other stack questions that shows the difference between git add -A
git add .
and git add -u
, but it doesn't have git add *
.
Note: I understand what it means to use the asterisk as a wildcard (add all files with a given extension). For example, git add *.html
would add all files that have a .html
extension (but ignore .css
, .js
, etc).
Thanks for the help!
add *
means add all files in the current directory, except for files whose name begin with a dot. This is your shell functionality and Git only ever receives a list of files.add .
has no special meaning in your shell, and thus Git adds the entire directory recursively, which is almost the same, but including files whose names begin with a dot.*
is not part of git - it's a wildcard interpreted by the shell.*
expands to all the files in the current directory, and is only then passed to git, whichadd
s them all..
is the current directory itself, andgit add
ing it will add it and the all the files under it.Using the dot
.
in the shell usually means "the current directory".When you use the asterisk
*
on a shell a feature calledfile-globbing
is utilized. E.g. on bash the functionglob()
is doing just that. The manpage for glob (man 7 glob
) states:That means when you pass arguments to any program on the commandline that contain
'?'
,'*'
or'['
, first globbing expands the wildcard pattern into a list of files and then gives these files as an argument to the program itself.The difference in meaning between
'git add .'
and'git add *'
is clearly described by Denis:git add
expects a list of files to be added. In the above example the shell expands*
or.
respectively and gives the result as a parameter to git add. Now the difference is that withgit add .
git will expand to the current directory whereasgit add *
triggers file globbing and such expands to all files and directories that do not start with a dot.For clarity, I put the answer in the table below:
Additional notes (inspired by the @reka18 comment):
Note 1.
git add -A
andgit add -u
commands performed without additional parameters would be additional refinement (subdirectory or mask indication for the file name) work in the range of the entire working directory (also if we execute the command in the working subdirectory of the directory).Note 2. The
.
and*
are respectively the directory path (current directory) and the wildcard, which clarify the path of the command. For example, if thegit add .
orgit add *
command is executed in some subdirectory of a working directory, then their action is only used within this subdirectory, not the entire working directory.Note 3. The
git add -A
andgit add -u
commands can be further refined by adding a path or mask for files, for example,git add -A app/controllers
orgit add -u app\styles\*
.