What is the difference between “git add .” and “git add -A”?

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

If there are only changed or new files, then there is no difference between …

git add .

and

git add -A .

The command “git add” adds files to the index to prepare the content staged for the next commit.  The difference is that the former updates changed files and add new files to the index.  It does not remove files from the index.  The latter adds changed files, add new files, and remove deleted files from the index.

So if you are starting a new depository and adding files to the index, the former is fine.

The -A flag in git add

The -A flag in git add is means “all”.  These three flags are equivalent …

-A
--all
--no-ignore-removal

According to git docs, they do …

“Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.”

Why you should include pathspec in “git add -A .”

Note that while git version 1.9.0 allow you to write …

git add -A

as an equivalent to …

git add -A .

You should start writing the latter with the dot as <pathspec>.  This is because …

“If no <pathspec> is given, the current version of Git defaults to “.”; in other words, update all files in the current directory and its subdirectories. This default will change in a future version of Git, hence the form without <pathspec> should not be used.” [from git documentation]

git add with the -u flag

The -u flag is “–update”.  It updates the index of changed files, and it removes index entries to match the working tree.  But it does not add new files to the index.