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
Clean vs Dirty Working Directory in Git
📖 Scenario: You are working on a project using Git for version control. You want to understand how to check if your working directory is clean (no changes) or dirty (has changes) before committing your work.
🎯 Goal: Learn how to check the status of your Git working directory to see if it is clean or dirty using Git commands.
📋 What You'll Learn
Create a new Git repository
Create a file and add it to the repository
Modify the file to make the working directory dirty
Use Git commands to check the working directory status
💡 Why This Matters
🌍 Real World
Checking if your working directory is clean or dirty helps you avoid committing unwanted changes and keeps your project history clean.
💼 Career
Understanding Git status is essential for developers and DevOps engineers to manage code changes safely and collaborate effectively.
Progress0 / 4 steps
1
Initialize a Git repository and create a file
Run the command git init to create a new Git repository. Then create a file named example.txt with the content Hello Git.
Git
Hint
Use git init to start a repository. Use echo to create the file with text.
2
Add the file to Git and commit
Run the command git add example.txt to stage the file. Then run git commit -m "Initial commit" to commit the file to the repository.
Git
Hint
Use git add to stage files and git commit -m to commit with a message.
3
Modify the file to make the working directory dirty
Change the content of example.txt by adding the line New line to make the working directory dirty.
Git
Hint
Use echo "New line" >> example.txt to append a line to the file.
4
Check if the working directory is clean or dirty
Run the command git status --short to see if the working directory is clean or dirty. The output should show the modified file.
Git
Hint
The output line starting with M means the file is modified and the working directory is dirty.
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
Step 1: Understand the meaning of a clean working directory
A clean working directory means no changes are pending to be committed or staged.
Step 2: Compare with other states
Untracked files, staged changes, or conflicts mean the directory is dirty, not clean.
Final Answer:
There are no changes to commit; all files are saved in Git. -> Option D
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
Step 1: Identify the command to check working directory state
The command git status shows staged, unstaged, and untracked changes.