Bird
Raised Fist0
Gitdevops~20 mins

Working directory state in Git - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Working Directory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Identify the output of 'git status' after file modification
You have a Git repository. You modified a tracked file named app.py but have not staged the changes yet. What will be the output of git status?
Git
git status
A
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

	modified:   app.py
B
On branch main
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:   app.py

no changes added to commit (use "git add" and/or "git commit -a")
C
On branch main
nothing to commit, working tree clean
Dfatal: not a git repository (or any of the parent directories): .git
Attempts:
2 left
💡 Hint
Think about what happens when you modify a file but do not stage it.
🧠 Conceptual
intermediate
1:30remaining
Understanding the working directory vs staging area
Which statement correctly describes the difference between the working directory and the staging area in Git?
AThe working directory is where you edit files, and the staging area is where you prepare changes to be committed.
BThe working directory contains files as they are in the last commit, and the staging area holds files with uncommitted changes.
CThe staging area is a backup of the working directory, and the working directory is the repository history.
DThe working directory is a remote copy of the repository, and the staging area is the local repository.
Attempts:
2 left
💡 Hint
Think about where you make changes and where you mark changes for commit.
Troubleshoot
advanced
2:00remaining
Diagnosing untracked files after git add
You ran git add README.md but git status still shows README.md as untracked. What is the most likely cause?
AREADME.md is ignored by a .gitignore rule.
BThe file has been deleted from the working directory.
CYou have not committed the file yet, so it remains untracked.
DYou ran <code>git add</code> in a different directory than where README.md is located.
Attempts:
2 left
💡 Hint
Check if the file is excluded by Git rules.
🔀 Workflow
advanced
2:30remaining
Sequence to discard changes in working directory
You accidentally modified a file config.yaml and want to discard all changes, restoring it to the last committed state. Which sequence of commands achieves this?
A2,4,1,3
B1,4,2,3
C1
D4,2,3,1
Attempts:
2 left
💡 Hint
Think about the simplest way to discard unstaged changes.
Best Practice
expert
3:00remaining
Best practice to keep working directory clean in a team
In a team project, what is the best practice to ensure the working directory stays clean and avoids conflicts before starting new work?
AIgnore changes in the working directory and work directly on the remote repository.
BDelete the working directory and clone the repository fresh each time.
CAlways commit all changes immediately, even incomplete work.
DUse <code>git stash</code> to save unfinished changes before switching branches or pulling updates.
Attempts:
2 left
💡 Hint
Think about temporarily saving work without committing.

Practice

(1/5)
1. What does the git status command show you about your working directory?
easy
A. It shows which files are new, modified, or staged for commit.
B. It deletes all untracked files from the directory.
C. It permanently commits all changes to the repository.
D. It resets the repository to the last commit.

Solution

  1. Step 1: Understand the purpose of git status

    This command checks the current state of the working directory and staging area.
  2. Step 2: Identify what git status reports

    It lists new files, modified files, and files staged for commit, helping you track changes.
  3. Final Answer:

    It shows which files are new, modified, or staged for commit. -> Option A
  4. Quick Check:

    Working directory changes = git status output [OK]
Hint: Remember: git status shows current file changes and staging [OK]
Common Mistakes:
  • Confusing git status with git commit
  • Thinking git status deletes files
  • Assuming git status changes files automatically
2. Which of the following commands correctly stages a file named app.js for commit?
easy
A. git commit app.js
B. git status app.js
C. git add app.js
D. git push app.js

Solution

  1. Step 1: Identify the command to stage files

    The git add command is used to add files to the staging area.
  2. Step 2: Confirm the correct syntax for staging a specific file

    Using git add app.js stages the file named app.js for the next commit.
  3. Final Answer:

    git add app.js -> Option C
  4. Quick Check:

    Stage files = git add [OK]
Hint: Use git add to stage files before committing [OK]
Common Mistakes:
  • Using git commit to stage files
  • Trying to use git status to stage
  • Using git push before commit
3. Given the following sequence of commands, what will git status show about index.html?
echo 'Hello' > index.html
git add index.html
echo 'World' >> index.html
git status
medium
A. index.html is staged and has unstaged changes.
B. index.html is deleted.
C. index.html is untracked.
D. index.html is staged and unchanged.

Solution

  1. Step 1: Analyze the commands on index.html

    First, 'Hello' is written and the file is staged with git add. Then 'World' is appended, modifying the file after staging.
  2. Step 2: Understand git status output

    Git will show index.html as staged (with 'Hello') but also as modified (unstaged changes with 'World').
  3. Final Answer:

    index.html is staged and has unstaged changes. -> Option A
  4. Quick Check:

    Modified after staging = staged + unstaged changes [OK]
Hint: Changes after git add show as unstaged modifications [OK]
Common Mistakes:
  • Assuming staging updates automatically after file change
  • Thinking file is untracked after git add
  • Confusing staged with committed
4. You ran git add README.md but git status still shows README.md under 'Changes not staged for commit'. What is the likely cause?
medium
A. README.md is ignored by .gitignore.
B. You modified README.md after running git add.
C. You committed README.md already.
D. README.md is deleted from the working directory.

Solution

  1. Step 1: Understand git add and file modification

    Running git add stages the current file state. If the file changes after, those changes are unstaged.
  2. Step 2: Interpret git status showing unstaged changes

    If README.md appears under 'Changes not staged for commit', it means it was modified after staging.
  3. Final Answer:

    You modified README.md after running git add. -> Option B
  4. Quick Check:

    Modify after add = unstaged changes shown [OK]
Hint: Modify after git add causes unstaged changes [OK]
Common Mistakes:
  • Assuming git add stages future changes automatically
  • Thinking .gitignore affects already tracked files
  • Confusing committed files with staged files
5. You want to prepare a commit but accidentally staged a large file secret.txt. How can you remove it from the staging area without deleting the file from your working directory?
hard
A. git checkout secret.txt
B. git rm secret.txt
C. git clean secret.txt
D. git reset secret.txt

Solution

  1. Step 1: Understand the difference between unstaging and deleting

    To remove a file from staging but keep it in the working directory, you must unstage it.
  2. Step 2: Identify the correct command to unstage a file

    git reset secret.txt removes the file from the staging area without deleting it from disk.
  3. Final Answer:

    git reset secret.txt -> Option D
  4. Quick Check:

    Unstage file = git reset filename [OK]
Hint: Use git reset to unstage files without deleting [OK]
Common Mistakes:
  • Using git rm deletes the file from disk
  • Using git checkout resets file content, not staging
  • Using git clean deletes untracked files