What is the difference between commands git add *
and git add .
when I put parameters *
and .
accordingly? What list of files system returns in both cases?
What is the difference between commands git add *
and git add .
when I put parameters *
and .
accordingly? What list of files system returns in both cases?
*
is a bash glob. It will expand to all files in the directory you're in, excluding dotfiles (files that start with a dot (.
))..
means the current directory.The result can be quite different depending on the content of your directory and if you have a
.gitignore
file.Consider you have the following files and directories in your directory:
When you run
git add *
, the glob is expanded before the git command runs. So what the git command receives is the following:This causes four problems here.
some-file-that-is-in-gitignore
cannot be added and will ask you to add the force (-f
) argument if you really want to add it..dotfile-that-must-be-committed
and.gitignore
were not added as*
does not expand to dotfiles.*
can never expand to those, so deleted files will not get staged.*
can never expand to the old name but it will expand to the new one. So what git will see is that you added a new file, and since the old name did not get staged you will end up with the same file existing twice, with the old name and the new name.However, running
git add .
tells git to add the current directory you're in without specifying which file to add. In this case, git will check the.gitignore
file and recursively add all files not mentioned in.gitignore
.In summary:
git add .
notgit add *
.Even better:
git add full/file/paths
so you don't add stuff by mistake that isn't ready to be added.And even much better:
git add -p
to review your changes and pick and choose which patches you want to be added.Something else not pointed out by current answers would be that
git add *
will not notice if you've deleted or renamed any files, butgit add .
will.Short Summary
git 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.git 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.Answer adapted from stackoverflow