0
0
Gitdevops~20 mins

git add with patterns and directories - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Add Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What files are staged after running this command?
Given a directory with files:
  • src/app.js
  • src/utils.js
  • test/app.test.js
  • README.md

What files will be staged after running:
git add src/*.js
Asrc/app.js and src/utils.js
Bsrc/app.js only
Csrc/app.js, src/utils.js, and test/app.test.js
DAll .js files in the repo
Attempts:
2 left
💡 Hint
The pattern matches files only in the specified directory, not subdirectories.
💻 Command Output
intermediate
2:00remaining
What is the effect of this git add command?
Assuming the current directory contains:
  • docs/intro.md
  • docs/setup.md
  • docs/images/logo.png

What files will be staged after:
git add docs/*.md
ANo files staged, pattern is invalid
Bdocs/intro.md, docs/setup.md, and docs/images/logo.png
COnly docs/intro.md
Ddocs/intro.md and docs/setup.md
Attempts:
2 left
💡 Hint
The pattern '*.md' matches markdown files only in the specified directory.
Configuration
advanced
2:00remaining
How to stage all files recursively in a directory?
You want to stage all files inside the 'src' directory and all its subdirectories. Which command achieves this?
Agit add src/**/*.js
Bgit add src/*
Cgit add src/
Dgit add src/*.**
Attempts:
2 left
💡 Hint
Adding a directory stages all files inside it recursively.
Troubleshoot
advanced
2:00remaining
Why does this git add command not stage files in subdirectories?
You run:
git add logs/*.log
But files in 'logs/2024/' are not staged. Why?
AThe pattern '*.log' matches only files directly inside 'logs', not in subdirectories
BGit does not support adding files with patterns
CThe command needs sudo privileges to add files in subdirectories
DThe files in 'logs/2024/' are ignored by .gitignore
Attempts:
2 left
💡 Hint
Patterns without recursive wildcards do not match files in subfolders.
🔀 Workflow
expert
3:00remaining
Which command stages only .js files in all subdirectories of 'src'?
You want to stage all .js files inside 'src' and any nested folders. Which command works correctly?
Agit add src/*.js
Bgit add 'src/**/*.js'
Cgit add src/
Dgit add src/*/*.js
Attempts:
2 left
💡 Hint
Use double star '**' for recursive matching in supported shells.