Git Add
Last updated
git add moves changes into the staging area (the index), marking them to be included in your next commit. You can stage a single file, everything at once with git add ., or pick individual chunks interactively with -p. Staging is the step between editing files and committing them.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git add file.txt | Stage one file |
git add . | Stage all changes in the current folder |
git add -A | Stage all changes in the whole repo |
git add -p | Stage selected chunks interactively |
git add *.js | Stage files matching a pattern |
git restore --staged file.txt | Unstage a file (keep changes) |
Common cases
| Goal | Command |
|---|---|
| Stage everything | git add . |
| Stage part of a file | git add -p |
| Unstage a file | git restore --staged file.txt |
| See what's staged | git status |
Git add FAQ
What does git add do?
It stages changes - copying them into the index so they'll be part of your next commit. Editing a file doesn't stage it; you run
git add <file> to mark it ready. Then git commit records exactly what's staged. Staging lets you commit some changes while leaving others for later.What's the difference between git add . and git add -A?
git add . stages changes in the current directory and below, including new, modified, and deleted files. git add -A stages changes across the entire repository regardless of your current directory. In a repo's root the two behave the same; they differ when you're in a subfolder.How do I stage only part of a file?
Use
git add -p (patch mode). Git walks you through each change ("hunk") and asks whether to stage it, so you can split unrelated edits in one file into separate commits. Press y to stage a hunk, n to skip it, s to split it further.How do I unstage a file?
Run
git restore --staged <file> (modern Git) or git reset <file> (older). Both remove the file from the staging area while keeping your edits in the working tree - the opposite of git add.Can I practice this online?
Yes. Open the terminal playground to run
git add in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers staging and committing step by step.