Git add Command
In this page:
Staging a Single File
To stage exactly one file, run git add <filename> with its exact path -- this copies that file's current contents into the staging area as a candidate for your next commit, without touching anything else you may have changed.
Example: Staging a Single File
git add index.html
Staging Multiple Files
You're not limited to one file at a time -- git add file1.txt file2.txt stages several specific files in a single command, which is handy when you've touched a few related files but want to leave the rest untouched.
Example: Staging Multiple Files
git add file1.txt file2.txt
Staging All Changes
When you've modified files scattered across many folders, staging each one individually is tedious -- git add . (stage everything in and below the current folder) or git add -A (stage every change in the whole repository) handles it in one shot.
Example: Staging All Changes
git add .
git add -A
Staging by File Type
Wildcards let you stage by pattern instead of by name -- git add *.js stages every JavaScript file in the current directory, which is useful when you want to commit only code changes and deliberately leave config or data files unstaged.
Example: Staging by File Type
git add *.js
Interactive Staging
Interactive staging (git add -p) walks you through a file's changes in small chunks called hunks, letting you accept or skip each one individually -- essential when a single file mixes an unrelated debug print with the real fix you want to commit.
Example: Interactive Staging
git add -p
Chapter Quiz — Complete all 18 topics to unlock
0/18 topics done
Complete these topics first:
- Git init Command
- Git New Files
- Git Staging Environment
- Git clone Command
- Git status Command
- Git help Command
- Git add Command
- Git commit Command
- Git tags Command
- Git stash Command
- Git log Command
- Git diff Command
- Git show Command
- Git rm Command
- Git mv Command
- Git restore Command
- Git clean Command
- Git ignore (.gitignore)