CurriculumGit Basicsgit add — Staging Changes
Lesson 4 of 667%
Beginner7 min+70 XP

git add — Staging Changes

git add moves changes from your working directory into the staging area (also called the index). Think of it as preparing a package — you carefully choose what goes in before sealing it with a commit.

01.The Staging Area Explained

The staging area sits between your working files and the repository. It gives you a chance to craft the perfect commit — grouping related changes together and leaving unrelated work for later. This two-step workflow (add then commit) is one of Git's most powerful features.

Git's Three Areas
📁
Working Dir
Your files
→ git add
📋
Staging Area
Prepared
→ git commit
🗄️
Repository
.git/ history

02.Selective Staging with -p

git add -p (patch mode) lets you stage individual lines or "hunks" within a file. You can make 10 changes in one file but only stage 3 of them for this commit. This is how experienced developers write clean, focused commit histories even while working messily.

Commit Timeline
a1b2c3d
init
b2c3d4e
feat
c3d4e5f
fix
d4e5f6a
HEAD

Commands

commands — click to reveal output
$
git add README.md
Stage a single specific file
$
git add src/
Stage all files inside a folder
$
git add .
Stage ALL changes in the current directory
$
git add *.js
Stage all JavaScript files using a glob pattern
$
git add -p
Interactively choose which changes (hunks) to stage
$
git status
See what is staged vs unstaged
▼ show output
KNOWLEDGE CHECK

What is the main purpose of the staging area?

Rate this lesson:
PreviousNext Lesson