0
0
GitComparisonBeginner · 3 min read

Git add . vs git add -A: Key Differences and When to Use Each

The git add . command stages new and modified files in the current directory and its subdirectories but ignores deleted files. In contrast, git add -A stages all changes including new, modified, and deleted files across the entire repository.
⚖️

Quick Comparison

Here is a quick side-by-side comparison of git add . and git add -A to highlight their key differences.

Featuregit add .git add -A
Scope of filesCurrent directory and subdirectoriesEntire repository
Includes deleted filesNoYes
Includes new filesYesYes
Includes modified filesYesYes
Common use caseAdd new and changed files locallyAdd all changes including deletions globally
⚖️

Key Differences

git add . stages all new and modified files only within the current directory and its subdirectories. It does not stage file deletions, so if you removed files, those deletions will not be included in the next commit.

On the other hand, git add -A stages all changes across the entire repository, including new files, modifications, and deletions. This means it tracks removed files and prepares them for commit, which git add . does not do.

Another difference is the scope: git add . works relative to your current folder, while git add -A affects the whole project regardless of your location in the directory tree.

💻

git add . Code Example

bash
git add .
Output
Stages new and modified files in the current directory and below, but ignores deletions.
↔️

git add -A Equivalent

bash
git add -A
Output
Stages all changes (new, modified, deleted) across the entire repository.
🎯

When to Use Which

Choose git add . when you want to quickly stage new and modified files only in your current working folder without affecting deletions or files outside this folder.

Choose git add -A when you want to stage every change in your entire project, including file deletions, ensuring your commit fully reflects all modifications.

For most complete commits, git add -A is safer to avoid accidentally missing deleted files.

Key Takeaways

git add . stages new and modified files only in the current directory and ignores deletions.
git add -A stages all changes including deletions across the entire repository.
Use git add -A to ensure all changes are included in your commit.
Use git add . for quick staging limited to your current folder.
Remember the scope difference: local folder vs entire project.