The command git add [--all|-A]
appears to be identical to git add .
. Is this correct? If not, how do they differ?
Git – Difference between “git add -A” and “git add .”
gitgit-add
Related Topic
- Git – How to undo ‘git add’ before commit
- Git – How to undo the most recent local commits in Git
- Git: How to force “git pull” to overwrite local files
- Git – Delete commits from a branch in Git
- Git – Move the most recent commit(s) to a new branch with Git
- Git – How to check out a remote Git branch
- Git – How to delete a Git branch locally and remotely
- Git – How to rename a local Git branch
Best Answer
This answer only applies to Git version 1.x. For Git version 2.x, see other answers.
Summary:
git add -A
stages all changesgit add .
stages new files and modifications, without deletions (on the current directory and its subdirectories).git add -u
stages modifications and deletions, without new filesDetail:
git add -A
is equivalent togit add .; git add -u
.The important point about
git add .
is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.git add -u
looks at all the already tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.git add -A
is a handy shortcut for doing both of those.You can test the differences out with something like this (note that for Git version 2.x your output for
git add .
git status
will be different):