Tracking Changes: git status and Staging with git add0%

Tracking Changes: git status and Staging with git add

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Tracking Changes: git status and Staging with git add

In Git, files do not automatically jump from your text editor into the permanent commit history. You must explicitly inspect your changes using git status and stage them using git add. This deliberate workflow gives you total control over what enters your project history.


1. Checking Status with git status

The git status command displays the exact state of your working directory and staging area relative to your last commit:

Bash / Terminal
git status

Understanding Status Outputs:

When you run git status, Git categorizes files into three distinct sections:

  1. 1
    Changes to be committed (Staged): Files added to the staging area with git add, ready for the next commit.
  2. 2
    Changes not staged for commit (Modified): Tracked files that have been edited on disk, but not yet staged.
  3. 3
    Untracked files: Brand new files that have never been committed or staged before.

Example Terminal Output:

Output
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: src/auth.js
 
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: package.json
 
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.txt

Pro Tip: Compact Short Status (-s or --short)

Bash / Terminal
git status -s

Output flags:

  • ?? : Untracked file
  • M (space then M in red) : Modified in working tree, not staged
  • M (green M then space) : Staged and ready to commit
  • MM : Staged, but modified again in working directory after staging!

2. Staging Changes with git add

The git add command copies changes from the Working Directory into the Staging Area (The Index):

Common git add Variations:

Bash / Terminal
# 1. Stage a single specific file
git add index.html
 
# 2. Stage multiple files explicitly
git add app.js styles.css src/components/Header.jsx
 
# 3. Stage all files in a specific folder
git add src/api/
 
# 4. Stage ALL modified, deleted, and untracked files across the entire repo
git add .
# Or equivalently:
git add -A
Important Warning
[!WARNING] Blindly running git add . without checking git status first is dangerous! You risk accidentally staging sensitive environment files (.env), database passwords, or bloated dependencies (node_modules). Always review git status first.

3. Advanced Staging: Interactive Patch Staging (git add -p)

What if you made 20 lines of changes in app.js, but 10 lines belong to a bug fix and 10 lines belong to an unfinished new feature? You can stage individual "hunks" (chunks) interactively using the patch flag:

Bash / Terminal
git add -p app.js

Git will display each modified chunk and prompt:

  • y : stage this hunk
  • n : do not stage this hunk
  • s : split this hunk into smaller pieces
  • q : quit interactive staging

4. Unstaging Files (git restore --staged)

If you accidentally staged a file that shouldn't be in the commit:

Bash / Terminal
# Unstage file (moves it back from Staging Area to Modified in Working Tree)
git restore --staged unwanted_file.js
 
# Legacy syntax (older Git versions < 2.23):
git reset HEAD unwanted_file.js

Interactive Quiz

Practice Quiz

Question 1
What information is provided by running git status?
Question 2
What does the command git add . do?
Question 3
In git status -s (short status), what does a green M on the left followed by a space mean?
Question 4
Which command allows you to interactively review and stage individual hunks (parts) of a modified file?
Question 5
How do you safely remove a file from the staging area without losing the changes on your disk?
Next Lesson

Recording Snapshots: git commit and Semantic Commit Messages

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext