nerdexam
CompTIA

XK0-004 · 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. Adding .tmp to .gitignore is the proper way to permanently exclude temporary files from Git tracking without deleting them or using invalid command syntax.

Scripting, Containers and Automation

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

(30 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    93% (28)

Why each option

Adding .tmp to .gitignore is the proper way to permanently exclude temporary files from Git tracking without deleting them or using invalid command syntax.

Agit rm .tmp

git rm removes a file from Git's index but does not configure Git to ignore future .tmp files, so they would be tracked again the next time git add is run.

Bgit add -x .tmp *

git add does not support an -x exclusion flag - this is invalid syntax and would produce an error.

Cecho .tmp >> .gitignoreCorrect

Appending .tmp to .gitignore instructs Git to ignore all files matching that pattern across the repository. The .gitignore file is the standard Git mechanism for excluding file patterns, and using >> appends the rule without overwriting existing entries, making the exclusion persistent and applicable to all contributors.

Drm -rf .tmp

rm -rf permanently deletes files from the filesystem rather than configuring Git to exclude them, which is destructive and does not solve the tracking problem.

Concept tested: Git file exclusion with .gitignore patterns

Source: https://git-scm.com/docs/gitignore

Topics

#.gitignore#Git#file exclusion#version control

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice