Git’s add command has several variations — git add ., git add -A, and git add -u among them — that all stage changes but behave differently depending on scope and file type. Understanding which one does what can save you from committing incomplete changes or accidentally missing a deletion.
What Git Add Does
The git add command adds the content of specified files at the time the command runs, and if you make further changes afterward, you need to run it again for those changes to be included in the next commit. The variations differ mainly in scope — how much of your repository they touch — and in whether they capture file deletions.
git add .
git add . is scoped to your current location in the repository. It stages new files and modifications to existing tracked files in the current directory and its subdirectories, so what gets staged depends on which directory you run it from. One key limitation: git add . does not stage file deletions.
git add -A (or –all)
git add -A is the broader option. It stages all changes in the repository — including new, modified, and deleted files — regardless of the current directory. It behaves the same way no matter which directory it’s run from, since it isn’t limited to the current folder and its subdirectories.
Where the Two Commands Diverge
The practical difference shows up once you’re working outside the repository root. If you delete a file at the root of the repo and then run git add . from a subfolder, that deletion won’t get staged, since git add . only affects the current directory and subdirectories. git add -A, by contrast, will pick up that change regardless of where it’s executed.
That said, the two commands often produce identical results in one common scenario:
- If git add . is run from the repository’s root directory and no files have been deleted since the last commit, it produces the same result as git add -A.
git add -u
There’s a third option worth knowing when you want to stage changes without adding brand-new files. git add -u stages only modifications and deletions, but not new files — useful when you want to update tracked files without pulling in anything untracked.
Quick Reference
- git add . — use for staging changes in the current directory and its subdirectories.
- git add -A / git add –all — use for staging changes across the entire working directory.
- git add -u — stages modifications and deletions to tracked files only, skipping new files.
A Note on .gitignore
Regardless of which variation you use, Git respects your ignore rules. Both git add . and git add -A will ignore files listed in the repository’s .gitignore file. If you specifically need to stage an ignored file, you can use the –force option, since specifying an ignored file’s exact name without it will cause the add command to fail.
Join The Discussion
The gap between git add . and git add -A trips up a lot of people, especially when a deleted file quietly gets left out of a commit. Have you run into a case where the wrong add command caused a mismatch between your staged changes and what you actually intended to commit, and do you have a habit — like always running from the repo root, or checking git status first — that helps you avoid it?