XK0-004 · Question #171
An administrator is reviewing updates in the master online Git repository and notices a file named . The file contains passwords and should only be in the administrator's local repository, not the .ht
The correct answer is D. echo ".htaccess" >> .gitignore. Adding a filename to .gitignore tells Git to exclude that file from tracking and prevent it from being staged or pushed to any remote repository.
Question
An administrator is reviewing updates in the master online Git repository and notices a file named . The file contains passwords and should only be in the administrator's local repository, not the .htaccess online one. Which of the following would prevent this file from appearing online in the future?
Options
- Agit commit -m "File Update" -x .htaccess
- Bsed -i 's/#Preserve Hidden=True/Preserve Hidden=True/g' .git/config
- Cchown nobody:nodoby .htaccess
- Decho ".htaccess" >> .gitignore
How the community answered
(27 responses)- A4% (1)
- C4% (1)
- D93% (25)
Why each option
Adding a filename to .gitignore tells Git to exclude that file from tracking and prevent it from being staged or pushed to any remote repository.
The -x flag does not exist for git commit; there is no built-in commit option to exclude a specific file from being tracked.
The .git/config file controls repository settings such as remotes and branches, not file exclusions; editing it with sed in this way has no effect on which files Git tracks.
chown changes the file's OS-level ownership but has no effect on Git tracking; Git will continue to stage and push the file regardless of who owns it.
The .gitignore file is a special Git configuration file where listed filenames and patterns are excluded from staging and commits; appending '.htaccess' via echo ensures Git will no longer track or push the file to the remote repository in future operations.
Concept tested: Excluding sensitive files from Git with .gitignore
Source: https://git-scm.com/docs/gitignore
Topics
Community Discussion
No community discussion yet for this question.