How to add files to Git staging area
· Category: Git
Short answer
Use git add <file> to stage specific files or git add . to stage all changes in the current directory.
Steps
- Stage a single file:
git add filename.txt
- Stage all changes:
git add .
- Stage only modified files (not new untracked files):
git add -u
- Interactively stage changes:
git add -p
Tips
- Use
git add -pto review each chunk of changes before staging. git add -Astages all changes including deletions across the entire repository.- Staging allows you to craft clean, logical commits rather than dumping all changes at once.
Common issues
- Accidentally staging files: use
git reset HEAD <file>to unstage. - Large binary files: consider using Git LFS to avoid bloating the repository.