0
0
Gitdevops~20 mins

git add for staging files - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Add Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of staging a single file?
You run the command git add README.md in a repository. What is the immediate output shown by Git?
ANo output is shown; the file is staged silently.
BOutput: 'README.md added to staging area'
COutput: 'Changes to be committed:' followed by the file name
DOutput: 'Error: file not found'
Attempts:
2 left
💡 Hint
Think about what Git normally shows when you add files.
💻 Command Output
intermediate
1:30remaining
What happens when you stage all files with a wildcard?
You run git add *.txt in a directory with files: notes.txt, todo.txt, and image.png. What files get staged?
AOnly notes.txt and todo.txt are staged.
BNo files are staged; wildcard is not supported.
COnly image.png is staged.
DAll files including image.png are staged.
Attempts:
2 left
💡 Hint
Consider how shell wildcards work before Git sees the command.
Configuration
advanced
2:00remaining
Which command stages all modified and deleted files but not new untracked files?
You want to stage all changes except new untracked files. Which command achieves this?
Agit add -A
Bgit add -u
Cgit add .
Dgit add --all
Attempts:
2 left
💡 Hint
Look at the difference between -u and -A options.
Troubleshoot
advanced
2:00remaining
Why does git add fail with 'fatal: pathspec ... did not match any files'?
You run git add docs/*.md but get the error: 'fatal: pathspec 'docs/*.md' did not match any files'. What is the most likely cause?
AThe docs directory is not tracked by Git.
BGit does not support wildcards in <code>git add</code>.
CThere are no .md files in the docs directory.
DYou need to run <code>git init</code> first.
Attempts:
2 left
💡 Hint
Check if the files actually exist in the specified path.
Best Practice
expert
2:30remaining
Which command safely stages only parts of a file interactively?
You want to stage only some changes inside a file, not the whole file. Which command lets you do this interactively?
Agit add --force filename
Bgit add --all filename
Cgit add -u filename
Dgit add -p filename
Attempts:
2 left
💡 Hint
Look for the option that allows patch mode.