Difference Between git add -u, git add -A, and git add .
When working with Git, the git add
command is used to stage changes and prepare them for a commit. This article explains the differences between three common variants of the command: git add -u
, git add -A
, and git add .
.
Basic Usage of git add
The git add
command stages specified files for the next commit:
$ git add <file>
# Example
$ git add text.txt
You can also use wildcards such as *
to stage multiple files:
$ git add *.py # Stage all .py files in the current directory
Comparing git add -u
, git add -A
, and git add .
These command variants all stage multiple changes at once, but each behaves slightly differently.
git add -u
(--update
)
Stages changes to tracked files only (i.e., modified and deleted files) across the entire repository. New (untracked) files are not included.
git add -A
(--all
)
Stages all changes throughout the repository, including new, modified, and deleted files.
git add .
Stages all changes in the current directory and its subdirectories, including new, modified, and deleted files.
Note: In Git versions prior to 2.0, git add .
did not stage deleted files. This behavior was changed in later versions.
The following table summarizes the behavior:
New Files | Modified Files | Deleted Files | |
---|---|---|---|
git add -u |
✗ | ✓ | ✓ |
git add -A |
✓ | ✓ | ✓ |
git add . |
✓ | ✓ | ✓ (since Git 2.0) |
Additional Notes
Although git add -A
and git add .
may seem identical, there's a key difference:
git add -A
stages all changes in the entire repository, no matter where it's run from.git add .
stages changes only in the current directory and below.
For example, consider a repository with the following structure:
repository_dir
├── dir1
└── dir2
If you run git add .
from inside dir1
, changes in dir2
will not be staged.
In contrast, git add -A
stages all changes across the entire repository, regardless of the current directory.