Tyler Tyler - 2 months ago 27
Git Question

git add * (asterisk) vs git add . (period)

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 *
.

enter image description here

Note: I do understand what it means to use the asterisk as a wildcard (meaning to add all files with a gigven extension). For example,
git add *.html
would add all files that have a
.html
extension (but ignore
.css
,
.js
, etc).

Thanks for the help!

Answer

add * means add all files in the current directory, except for files, whose name begin with a dot. This is your shell functionality, actually, Git only receives a list of files.

add ., though, has no special meaning in your shell, and Git add the entire directory recursively, which is basically the same, but it also adds files whose name begin with a dot.

Comments