git add: Usage, Options & Common CI Errors
git add moves changes from your working tree into the staging area (the index).
Staging is how you choose exactly what goes into the next commit. The flags control scope; pathspecs control precision.
What it does
git add records the current content of files into the index so they will be part of the next commit. It does not commit anything by itself.
Common usage
Terminal
git add file.txt
git add . # everything under the current directory
git add -A # all changes incl. deletions, whole tree
git add -u # only already-tracked files
git add -p # interactively stage hunksOptions
| Flag | What it does |
|---|---|
| -A / --all | Stage adds, modifications, and deletions everywhere |
| -u / --update | Stage changes to tracked files only |
| -p / --patch | Choose hunks interactively |
| -f / --force | Add files that .gitignore would skip |
| -n / --dry-run | Show what would be added |
Common errors in CI
fatal: pathspec 'X' did not match any files - the path does not exist or is ignored. Check the working directory and whether .gitignore excludes it; use git add -f to override an ignore, or git status to see the real paths.
Related guides
git commit: Usage, Options & Common CI Errorsgit commit records staged changes as a new commit. Reference for -m, --amend, --no-verify, and the empty-comm…
git status: Usage, Options & Common CI Errorsgit status shows staged, unstaged, and untracked changes plus branch state. Reference for -s, --porcelain, -b…
git restore: Usage, Options & Common CI Errorsgit restore discards working-tree changes or unstages files. Reference for --staged, --source, --worktree, an…
git rm: Usage, Options & Common CI Errorsgit rm removes files from the working tree and the index. Reference for --cached, -r, -f, and the "has staged…