Staging Area

7.1 What is the Staging Area?

When you modify files in your project:
1. They start in the working directory (untracked or modified).
2. You add specific files to the staging area using git add.
3. You finalize them into the repository with git commit.
This gives you granular control over what goes into each commit.

Visualized:
1Working Directory → Staging Area → Repository 2(untracked files) (selected changes) (committed history)

7.2 Adding Files to the Staging Area

You can stage individual files or all changes at once.

Stage a single file:
1git add index.html

Stage all modified files:
1git add .

Stage specific file patterns:
1git add *.js

This makes only selected files part of the next commit — useful when you're working on multiple things at once but want clean, focused commits.

7.3 Checking the Staging Area Status

Use:
1git status

You'll see three categories:
Untracked files: new files not staged yet
Changes not staged for commit: modified but unstaged
Changes to be committed: staged and ready for commit
You can also preview exact staged changes:

You can also preview exact staged changes:
1git diff --staged

7.4 Removing Files from the Staging Area

To unstage a file (move it back to the working directory):
1git restore --staged <filename>

Example:
1git restore --staged main.py

This keeps your file changes in the working directory but removes them from the next commit — perfect if you added something by mistake.

7.5 Why the Staging Area Matters

Selective Commits: You can commit only specific changes rather than everything modified.
Review Before Commit: Ensures you don't accidentally save debug code or temporary edits.
Organized History: Enables clean commit messages tied to logical feature units.
Without the staging area, every change would go directly into commits — making history messy and harder to manage.

7.6 Useful Commands Recap

ActionCommand
Add a file to staginggit add <file>
Add all changesgit add .
See staged filesgit status
See staged diffgit diff --staged
Unstage a filegit restore --staged <file>

7.7 Key Takeaways

The staging area is Git's "review zone" — where you prepare what goes into your next commit.
Use git add to stage and git restore --staged to unstage changes.
Always run git status before committing to confirm what's being saved.
A clean, deliberate staging process keeps your Git history readable and professional.