0
0
Gitdevops~20 mins

Clean vs dirty working directory in Git - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Working Directory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Identify clean working directory status
You run git status in a repository. Which output indicates a clean working directory?
AOn branch main\nYour branch is ahead of 'origin/main' by 1 commit
BOn branch main\nChanges not staged for commit:\n modified: file.txt
COn branch main\nUntracked files:\n newfile.txt
DOn branch main\nnothing to commit, working tree clean
Attempts:
2 left
💡 Hint
Look for the phrase that says no changes are pending.
🧠 Conceptual
intermediate
2:00remaining
Difference between staged and unstaged changes
Which statement correctly describes the difference between staged and unstaged changes in Git?
AStaged changes are files deleted from the repository; unstaged changes are new files only.
BUnstaged changes are ready to be committed; staged changes are ignored by Git.
CStaged changes are ready to be committed; unstaged changes are modified files not yet added to the staging area.
DThere is no difference; both terms mean the same in Git.
Attempts:
2 left
💡 Hint
Think about what 'git add' does.
Troubleshoot
advanced
2:00remaining
Detecting dirty working directory with a script
You want to write a shell script to check if the Git working directory is dirty (has unstaged or staged changes). Which command correctly returns a non-empty output only if the directory is dirty?
Agit diff --name-only || git diff --cached --name-only
Bgit diff --quiet || git diff --cached --quiet
Cgit diff --quiet && git diff --cached --quiet
Dgit diff --name-only && git diff --cached --name-only
Attempts:
2 left
💡 Hint
Use commands that list changed files and combine with OR to detect any changes.
🔀 Workflow
advanced
2:00remaining
Handling dirty working directory before switching branches
You want to switch branches but your working directory is dirty. What is the safest way to switch branches without losing your changes?
ARun 'git stash' to save changes, switch branch, then 'git stash pop' to reapply changes.
BRun 'git reset --hard' to discard changes, then switch branch.
CSwitch branch directly with 'git checkout' ignoring changes.
DDelete the modified files manually, then switch branch.
Attempts:
2 left
💡 Hint
Think about saving your work temporarily.
Best Practice
expert
2:00remaining
Best practice for committing changes in a dirty working directory
You have multiple unrelated changes in your dirty working directory. What is the best practice to commit them properly?
ACreate a new branch for each change without staging selectively.
BUse 'git add -p' to stage changes interactively and commit logically separated changes in multiple commits.
CDelete unrelated changes and commit only one feature at a time.
DCommit all changes at once with a single message describing everything.
Attempts:
2 left
💡 Hint
Think about how to organize commits clearly.