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
Recall & Review
beginner
What does the command git add . do?
It stages all changes (new, modified, deleted files) in the current directory and all its subdirectories for the next commit.
Click to reveal answer
beginner
How can you stage all .txt files in the current directory using git add?
Use the pattern git add *.txt to stage all files ending with .txt in the current directory only.
Click to reveal answer
intermediate
What is the difference between git add * and git add .?
git add * stages all files and directories in the current directory but does not include hidden files or files in subdirectories. git add . stages all changes including hidden files in the current directory and subdirectories.
Click to reveal answer
beginner
How do you stage all files inside a specific directory named docs?
Use git add docs/ to stage all changes inside the docs directory and its subdirectories.
Click to reveal answer
intermediate
Can git add use wildcards to stage files recursively in subdirectories?
No, wildcards like *.txt only match files in the current directory. To stage files recursively, use git add . or specify directories.
Click to reveal answer
Which command stages all changes in the current directory and all subdirectories?
Agit add -p
Bgit add *
Cgit add *.txt
Dgit add .
✗ Incorrect
git add . stages all changes recursively in the current directory and subdirectories.
What does git add *.js do?
AStages all JavaScript files in all subdirectories
BStages all files including hidden ones
CStages all JavaScript files in the current directory only
DStages all files except JavaScript files
✗ Incorrect
The pattern *.js matches JavaScript files only in the current directory.
How to stage all files inside a folder named src?
Agit add src/
Bgit add src/*
Cgit add *.src
Dgit add .src
✗ Incorrect
Using git add src/ stages all files and folders inside src recursively.
Which command does NOT stage hidden files?
Agit add .
Bgit add *
Cgit add docs/
Dgit add -A
✗ Incorrect
git add * does not include hidden files (files starting with a dot).
To stage only modified parts of files interactively, which command is used?
Agit add -p
Bgit add .
Cgit add *
Dgit add --all
✗ Incorrect
git add -p lets you choose parts of files to stage interactively.
Explain how to use git add with patterns to stage specific file types.
Think about how shell wildcards work in file names.
You got /3 concepts.
Describe how to stage all changes inside a directory and its subdirectories using git add.
Consider how folders are referenced in commands.
You got /3 concepts.
Practice
(1/5)
1. What does the command git add src/ do?
easy
A. Removes the 'src' directory from the repository.
B. Stages only the 'src' directory itself, not its contents.
C. Commits changes in the 'src' directory immediately.
D. Stages all changes in the 'src' directory and its subdirectories.
Solution
Step 1: Understand the command context
The command git add src/ targets the directory named 'src'.
Step 2: Know how git add works with directories
Git stages all files and subdirectories inside 'src' recursively when adding a directory.
Final Answer:
Stages all changes in the 'src' directory and its subdirectories. -> Option D
Quick Check:
git add directory = stage all inside [OK]
Hint: Adding a directory stages all files inside it recursively [OK]
Common Mistakes:
Thinking it stages only the directory, not contents
Confusing add with commit
Assuming it deletes files
2. Which of the following is the correct command to stage all .txt files in the current directory using a pattern?
easy
A. git add txt.*
B. git add .txt*
C. git add *.txt
D. git add *txt
Solution
Step 1: Understand wildcard usage in git add
The asterisk (*) matches any characters, so *.txt matches all files ending with '.txt'.
Step 2: Check each option's pattern
git add *.txt correctly matches all '.txt' files. Others do not match the intended pattern.
Final Answer:
git add *.txt -> Option C
Quick Check:
Use * before extension to match all files [OK]
Hint: Use '*.ext' to add all files with that extension [OK]
What files will be staged after running git add docs/*.md?
medium
A. Only docs/intro.md and docs/setup.md
B. All files in project including app.js and README.md
C. No files, command fails due to pattern
D. Only docs/setup.md
Solution
Step 1: Analyze the pattern used
The pattern docs/*.md matches all files ending with '.md' inside the 'docs' directory only.
Step 2: Identify matching files
Inside 'docs', 'intro.md' and 'setup.md' match. Files outside 'docs' are not matched.
Final Answer:
Only docs/intro.md and docs/setup.md -> Option A
Quick Check:
Pattern matches files only inside specified directory [OK]
Hint: Pattern 'dir/*.ext' adds matching files only inside that directory [OK]
Common Mistakes:
Assuming files outside 'docs' are staged
Thinking pattern matches recursively
Believing command fails if pattern matches multiple files
4. You run git add docs/*.md but only docs/intro.md is staged, not docs/setup.md. What is the most likely cause?
medium
A. You need to add files one by one manually.
B. The file docs/setup.md is ignored by .gitignore.
C. Git add cannot stage files in subdirectories.
D. The pattern '*.md' only matches one file at a time.
Solution
Step 1: Understand why some files are not staged
If a file is ignored by .gitignore, git add will skip it even if the pattern matches.
Step 2: Check other options for correctness
Patterns can match multiple files; git add works recursively for directories; manual adding is not required.
Final Answer:
The file docs/setup.md is ignored by .gitignore. -> Option B
Quick Check:
Ignored files are skipped by git add [OK]
Hint: Check .gitignore if some matching files are not staged [OK]
Common Mistakes:
Believing patterns match only one file
Thinking git add can't stage multiple files
Assuming manual add is always needed
5. You want to stage all JavaScript files in the 'src' directory and all Markdown files in the 'docs' directory with one command. Which command achieves this?
hard
A. git add src/*.js docs/*.md
B. git add 'src/*.js docs/*.md'
C. git add src/*.js && git add docs/*.md
D. git add src/ docs/ *.js *.md
Solution
Step 1: Understand how to add multiple patterns in one command
Git add accepts multiple paths or patterns separated by spaces without quotes.
Step 2: Evaluate each option
git add src/*.js docs/*.md correctly lists both patterns separated by space. git add 'src/*.js docs/*.md' quotes patterns unnecessarily, which may cause shell to treat them literally. git add src/*.js && git add docs/*.md runs two commands, not one. git add src/ docs/ *.js *.md mixes directories and patterns incorrectly.
Final Answer:
git add src/*.js docs/*.md -> Option A
Quick Check:
Multiple patterns separated by space work in one git add [OK]
Hint: List multiple patterns separated by spaces in one git add command [OK]
Common Mistakes:
Using quotes that prevent shell expansion
Trying to combine commands with && instead of one command