Bird
Raised Fist0
Gitdevops~10 mins

Clean vs dirty working directory in Git - Visual Side-by-Side Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Clean vs dirty working directory
Start: Working Directory
Check for changes?
Clean
Ready for
This flow shows how Git checks your working directory for changes. If no changes, it's clean; if changes exist, it's dirty.
Execution Sample
Git
git status
# Shows if working directory is clean or dirty
This command checks the current state of your working directory and staging area.
Process Table
StepCommandWorking Directory StateGit Output SummaryNext Action
1git statusNo changes"working tree clean"Ready for next commit
2touch file.txtNew untracked file"Untracked files:" list shownAdd or ignore file
3git add file.txtFile staged"Changes to be committed:" list shownCommit or unstage
4echo 'change' > file.txtModified staged file"Changes not staged for commit:" list shownAdd changes or discard
5git commit -m 'Add file.txt'No changes"working tree clean"Ready for next commit
💡 Execution stops when working directory is clean and no changes are staged.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5
Working DirectoryCleanDirty (untracked file)Dirty (file staged)Dirty (file modified)Clean
Staging AreaEmptyEmptyfile.txt stagedfile.txt staged but modifiedEmpty
Key Moments - 3 Insights
Why does git status show 'working tree clean' even after creating a new file?
Because the new file is untracked and not staged yet, git status shows it under 'Untracked files' but the working tree is not clean until changes are staged or ignored (see execution_table step 2).
What does it mean when git status shows 'Changes to be committed'?
It means files are staged and ready to be committed. This is shown after 'git add' command (see execution_table step 3).
Why does modifying a staged file show 'Changes not staged for commit'?
Because the file was changed after staging, so the staged snapshot differs from the working directory. You need to add again to update the staging area (see execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the working directory state after step 3?
AClean
BDirty with staged files
CDirty with untracked files
DDirty with unstaged changes
💡 Hint
Check the 'Working Directory State' column at step 3 in the execution_table.
At which step does git status show 'working tree clean'?
AStep 1 and Step 5
BStep 2
CStep 3
DStep 4
💡 Hint
Look for 'working tree clean' in the 'Git Output Summary' column in the execution_table.
If you modify a staged file but do not run git add again, what will git status show?
ANo changes, working tree clean
BChanges to be committed
CChanges not staged for commit
DUntracked files
💡 Hint
Refer to step 4 in the execution_table where the file is modified after staging.
Concept Snapshot
Clean vs Dirty Working Directory in Git:
- Clean: No changes or all changes committed.
- Dirty: Untracked, modified, or staged changes exist.
- git status shows state: 'working tree clean' means clean.
- Use git add to stage changes.
- Modify after staging requires re-adding to update staging.
Full Transcript
This visual execution shows how Git determines if your working directory is clean or dirty. Starting with no changes, git status reports 'working tree clean'. Creating a new file makes the directory dirty with untracked files. Adding the file stages it, showing 'Changes to be committed'. Modifying the staged file again makes it dirty with unstaged changes. Committing clears all changes, returning to a clean state. Key points include understanding untracked vs staged vs modified states and how git status messages reflect these. This helps you know when your directory is ready for commit or needs more action.

Practice

(1/5)
1. What does it mean when your Git working directory is described as clean?
easy
A. There are conflicts from a merge.
B. There are untracked files present.
C. There are changes staged but not committed.
D. There are no changes to commit; all files are saved in Git.

Solution

  1. Step 1: Understand the meaning of a clean working directory

    A clean working directory means no changes are pending to be committed or staged.
  2. Step 2: Compare with other states

    Untracked files, staged changes, or conflicts mean the directory is dirty, not clean.
  3. Final Answer:

    There are no changes to commit; all files are saved in Git. -> Option D
  4. Quick Check:

    Clean working directory = no uncommitted changes [OK]
Hint: Clean means no changes to commit or stage [OK]
Common Mistakes:
  • Confusing staged changes with clean state
  • Thinking untracked files mean clean
  • Assuming conflicts mean clean
2. Which Git command correctly shows the current state of your working directory?
easy
A. git push origin main
B. git commit -m "status"
C. git status
D. git checkout

Solution

  1. Step 1: Identify the command to check working directory state

    The command git status shows staged, unstaged, and untracked changes.
  2. Step 2: Eliminate other commands

    git commit saves changes, git push uploads commits, git checkout switches branches or files.
  3. Final Answer:

    git status -> Option C
  4. Quick Check:

    Check working directory state = git status [OK]
Hint: Use 'git status' to see working directory changes [OK]
Common Mistakes:
  • Using git commit to check status
  • Confusing git push with status check
  • Using git checkout incorrectly
3. You run git status and see:
Changes not staged for commit:
modified: app.js

What is the state of your working directory?
medium
A. Dirty working directory with unstaged changes
B. Dirty working directory with staged changes
C. Clean working directory
D. Detached HEAD state

Solution

  1. Step 1: Interpret the git status output

    The message "Changes not staged for commit" means files are modified but not added to staging.
  2. Step 2: Determine working directory state

    Unstaged changes mean the directory is dirty, not clean, and changes are not staged.
  3. Final Answer:

    Dirty working directory with unstaged changes -> Option A
  4. Quick Check:

    Unstaged changes = dirty directory [OK]
Hint: Unstaged changes mean dirty directory [OK]
Common Mistakes:
  • Confusing unstaged with staged changes
  • Assuming clean when files are modified
  • Mixing detached HEAD with working directory state
4. You see this output after running git status:
On branch main
Changes to be committed:
modified: index.html

But you want to check if your working directory is clean. What should you do?
medium
A. Run git reset HEAD index.html to unstage changes
B. Run git commit to save changes
C. Run git add index.html again
D. Run git checkout index.html to stage changes

Solution

  1. Step 1: Understand the meaning of staged changes

    "Changes to be committed" means files are staged but not committed, so directory is dirty.
  2. Step 2: Unstage changes to check clean state

    Running git reset HEAD index.html unstages the file, showing if working directory has unstaged changes.
  3. Final Answer:

    Run git reset HEAD index.html to unstage changes -> Option A
  4. Quick Check:

    Unstage changes to check clean state [OK]
Hint: Unstage files with git reset HEAD to check clean state [OK]
Common Mistakes:
  • Adding files again instead of unstaging
  • Committing without checking unstaged changes
  • Using git checkout to stage files (wrong)
5. You modified two files: app.py and README.md. You staged app.py but not README.md. What will git status show?
hard
A. No changes to commit, working directory clean
B. Changes to be committed: app.py; Changes not staged for commit: README.md
C. Changes not staged for commit: app.py and README.md
D. Untracked files: app.py and README.md

Solution

  1. Step 1: Identify staged and unstaged files

    app.py is staged, so it appears under "Changes to be committed".
  2. Step 2: Identify unstaged files

    README.md is modified but not staged, so it appears under "Changes not staged for commit".
  3. Final Answer:

    Changes to be committed: app.py; Changes not staged for commit: README.md -> Option B
  4. Quick Check:

    Staged vs unstaged files shown separately [OK]
Hint: Staged files show as 'to be committed', unstaged as 'not staged' [OK]
Common Mistakes:
  • Assuming all modified files are staged
  • Confusing untracked with modified files
  • Thinking working directory is clean with staged changes