What is git add?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Git & GitHub basics — a prerequisite for any developer role.
Answer
git add moves changes from the working directory to the staging area (index), marking them to be included in the next commit. Variants: git add file.txt — stage a specific file; git add src/ — stage all changes in a directory; git add . — stage all changes in the current directory and subdirectories (new files + modifications + deletions); git add -A / --all — stage all changes everywhere in the repo (including deletions); git add *.js — stage all JS files; git add -p / --patch — interactively stage parts of a file (hunks) — extremely useful for making clean, focused commits even when you've changed multiple things in one file; git add -u — stage modifications and deletions but NOT new untracked files. After staging, verify with git status (shows what's staged in green, unstaged in red) or git diff --staged (shows exact diff of what will be committed). To unstage: git restore --staged file.txt (modern) or git reset HEAD file.txt (classic).
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Git & GitHub answers easy to follow.