Terminal GuideTerminal Guide

git add Command Guide

Stage changes for the next commit

5 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git add <file>Stage specific file
git add .Stage all changes
git add -AStage all (including deletes)

Selective

git add -pInteractive staging
git add -iInteractive mode
git add *.jsStage by pattern

Advanced

git add -uStage modified/deleted only
git add -nDry run (show what would be added)
git add -fForce add ignored files

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git add command adds changes to the staging area (index). This is the first step in the Git workflow before committing changes.

bash
# Stage a specific file
git add filename.js

# Stage multiple files
git add file1.js file2.js file3.js

# Stage all changes in current directory and subdirectories
git add .

# Stage all changes in the entire repository
git add -A
git add --all

Common Options

OptionDescription
-A, --allStage all changes (new, modified, deleted)
-p, --patchInteractively choose hunks to stage
-u, --updateStage modified and deleted files only
-n, --dry-runShow what would be added without adding
-f, --forceAdd ignored files
-i, --interactiveInteractive mode

Interactive Staging

Use git add -p to stage changes interactively, selecting which parts of files to include:

bash
$ git add -p
diff --git a/src/app.js b/src/app.js
@@ -1,5 +1,6 @@
 const app = {
   name: 'MyApp',
+  version: '2.0',
   init() {
     console.log('Starting...');
   }
Stage this hunk [y,n,q,a,d,s,e,?]?

Interactive Commands

  • y - Stage this hunk
  • n - Do not stage this hunk
  • q - Quit; do not stage this or remaining hunks
  • a - Stage this and all remaining hunks in file
  • s - Split this hunk into smaller hunks
  • e - Manually edit this hunk
Tip
Interactive staging with git add -p is excellent for creating focused, atomic commits by selecting only related changes.

Staging Patterns

bash
# Stage all JavaScript files
git add *.js

# Stage all files in a directory
git add src/

# Stage all test files recursively
git add **/*.test.js

# Stage all new and modified files (not deleted)
git add .

# Stage all modified and deleted files (not new)
git add -u

Practical Examples

bash
# Typical workflow: stage and commit
git add .
git commit -m "Add new feature"

# Stage specific changes interactively
git add -p src/app.js

# Preview what will be staged
git add -n .

# Stage all changes except untracked files
git add -u

# Force add a file that's in .gitignore
git add -f build/config.json

# Undo staging (unstage all files)
git restore --staged .

Frequently Asked Questions

What is the difference between "git add ." and "git add -A"?

In Git 2.x, they are essentially the same when run from the root directory. "git add -A" stages all changes (new, modified, deleted) from the entire repository, while "git add ." stages changes from the current directory and below.

How do I unstage a file after git add?

Use "git restore --staged <file>" or "git reset HEAD <file>" to unstage a file while keeping the changes in your working directory.

Can I add only part of a file's changes?

Yes! Use "git add -p <file>" to interactively select which hunks (sections) of changes to stage. You can stage some changes while leaving others unstaged.

How do I add files that are in .gitignore?

Use "git add -f <file>" to force add ignored files. However, consider if you really need to track these files.

What does "git add -u" do?

It stages all modifications and deletions of tracked files, but does NOT add new untracked files. Useful when you want to commit changes to existing files only.

Summary

git add is essential for staging changes before committing. Master interactive staging for cleaner, more focused commits.

Quick Reference

  • git add <file> - Stage specific file
  • git add . - Stage all changes
  • git add -p - Interactive staging
  • git add -u - Stage modified/deleted only
  • git add -A - Stage everything

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles