Synopsis
git add [-p] [-A] [-u] [--] [<pathspec>...]
Description
The git add command moves changes from your working tree into the staging area (also called the index). The staging area is a snapshot of what will go into the next commit. By staging changes explicitly, Git lets you craft commits that contain exactly the work you want to record — even if your working tree has other unrelated edits in progress.
git add can stage entire files, parts of files (with -p), or directories. It does not commit anything; it only updates the index. The most common workflow is: edit, git status, git add, git commit. Mastering git add, especially its interactive modes, is one of the best ways to make your commit history readable and easy to review.
In day-to-day use, git add integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git add --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git add interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git add's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
-A, --all | Stage all changes in the working tree, including deletions and new files. |
-u, --update | Stage modifications and deletions to tracked files only — ignores new files. |
-p, --patch | Interactively choose hunks of changes to stage. |
-n, --dry-run | Show what would be staged without actually staging. |
-f, --force | Add files even if they match .gitignore. |
-i, --interactive | Open a menu-driven interface for staging. |
--intent-to-add / -N | Record an intent to add a file so its diff appears. |
Examples
git add README.md src/main.c
# Stage two specific files
git add -A
# Stage everything: new, modified, and deleted files
git add -p
# Interactively review and stage chunks one by one
git add 'src/**/*.js'
# Stage all JavaScript files under src using a pathspec
Common Mistakes
Running git add . blindly often stages files you didn't intend — log files, build artifacts, secret keys. Use git status first and consider -p for sensitive changes. Another common confusion: git add -u will not pick up new files, while git add . will. After staging, if you change a file again, those subsequent edits are not staged until you re-run git add.
Related Commands
git commit, git status, git restore, git reset