Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is the difference between git add * and git add?

Both git add . and git add -A will stage all new, modified and deleted files in the newer versions of Git. The difference is that git add -A stages files in "higher, current and subdirectories" that belong to your working Git repository. But doing a git add .

What does git add period?

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.

Does git add take a long time?

Because the files checked are restricted to pathspec, adding individual files makes no measurable impact but on a Windows repo with ~200K files, ' git add . ' drops from 6.3 seconds to 3.3 seconds for a 47% savings.

What is the dot in git add?

The period in git add . means the current directory and all files within it, recursively.


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, which adds them all. . is the current directory itself, and git adding 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 called file-globbing is utilized. E.g. on bash the function glob() is doing just that. The manpage for glob (man 7 glob) states:

DESCRIPTION

Long ago, in UNIX V6, there was a program /etc/glob that would expand 
wildcard patterns.  Soon afterward this became a shell built-in.
These days there is also a library routine glob(3) that will perform this 
function for a user program.

Wildcard matching

A string is a wildcard pattern  if it contains one of the characters '?', '*' or '['. 

Globbing

Globbing is the operation that expands a wildcard pattern 
into the list of pathnames matching the pattern.

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 with git add . git will expand to the current directory whereas git 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:

enter image description here

Additional notes (inspired by the @reka18 comment):

Note 1. git add -A and git 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 the git add . or git 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 and git add -u commands can be further refined by adding a path or mask for files, for example, git add -A app/controllers or git add -u app\styles\*.


  • git add -A (--all) Adds everything, so that everything in your folder on disk is represented in the staging area

  • git add . Stages everything, but does not remove files that have been deleted from the disk

  • git add * Stages everything, but not files that begin with a dot & does not remove files that have been deleted from the disk

  • git add -u (--update) Stages only Modified Files, removes files that have been deleted from disk, does not add new

  • git add <file name 1> <file name 2> Adds only certain file(s)