Understanding git add: A Developer’s Guide to Staging Smarter


Whether you're a beginner or you've been using Git for years, chances are you've run git add . more times than you can count. But did you know there are several ways to use git add, each with a specific purpose?

In this post, I’ll walk through the most useful git add commands, explain what they do and help you choose the right one for different situations.


git add <file>

Adds a specific file to the staging area

git add index.js

Use when you want to stage only one file or select individual files for commit.


git add .

Adds all new and modified files in the current directory and its subdirectories

git add .

Use when you want to stage all changes, including untracked files (but not deletions).


git add -A

Adds all changes: new, modified and deleted files

git add -A

Use when you want to stage everything - this is the most complete staging command.


git add -u

Adds only modified and deleted files - ignores untracked files

git add -u

Use when you've deleted or edited files, but don’t want to include new files yet.


git add -p

Interactive mode - stage file changes chunk by chunk

git add -p

Use when you want to review and stage parts of a file instead of the whole thing. Great for clean commits!


git add -n

Dry run -shows what will be added without actually staging anything

git add -n .

Use when you want to preview changes before committing them.


Quick Summary Table

CommandWhat It StagesBest Used For
git add <file>A single fileSelective staging
git add .New and modified filesMost changes, quickly
git add -AAll changes (add, modify, delete)Full clean-up before a commit
git add -uModified and deleted files onlyAvoid adding new files
git add -pInteractive (hunk-by-hunk) stagingCleaner commits with reviewed changes
git add -nNothing (just simulates)Safe previews

Knowing the right git add command gives you better control over your commits and helps you write cleaner, more focused commit messages.

📌 Tip: Always double-check your staging with git status before committing , it saves headaches!


0
Subscribe to my newsletter

Read articles from Ganiyatu Sanuusi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ganiyatu Sanuusi
Ganiyatu Sanuusi

Tech with Ghaniya is a space where I share real-world solutions to tech problems I’ve faced — and go further by offering practical tips, tutorials, and tools to help others learn, build, and grow. From software development to everyday tech challenges, if it helps someone level up, it’s worth writing about