XK0-005 · Question #238
A Linux administrator needs to add some files in a directory to the Git repository but must exclude some local .tmp files that are occasionally created by the scripts. Which of the following is the…
The correct answer is C. echo .tmp >> .gitignore. To prevent specific temporary files from being tracked by Git, the most effective method is to add their pattern to the project's .gitignore file.
Question
A Linux administrator needs to add some files in a directory to the Git repository but must exclude some local .tmp files that are occasionally created by the scripts. Which of the following is the BEST way to accomplish this task?
Options
- Agit rm .tmp
- Bgit add -x .tmp *
- Cecho .tmp >> .gitignore
- Drm -rf .tmp
How the community answered
(48 responses)- A2% (1)
- B15% (7)
- C77% (37)
- D6% (3)
Why each option
To prevent specific temporary files from being tracked by Git, the most effective method is to add their pattern to the project's .gitignore file.
`git rm` is used to remove files from the Git repository and working directory, not to prevent them from being tracked in the first place.
`git add -x` is not a valid Git command for excluding specific file types during the staging process.
Appending `.tmp` to the `.gitignore` file tells Git to ignore any file or directory matching this pattern when performing operations like `git add`. This prevents the temporary files from being staged or committed to the repository, fulfilling the requirement to exclude them.
`rm -rf .tmp` would delete the `.tmp` files from the filesystem, which is not the goal; the goal is to exclude them from Git tracking while they may still exist locally.
Concept tested: Git file exclusion with .gitignore
Source: https://git-scm.com/docs/gitignore
Topics
Community Discussion
No community discussion yet for this question.