nerdexam
CompTIA

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.

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

(48 responses)
  • A
    2% (1)
  • B
    15% (7)
  • C
    77% (37)
  • D
    6% (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.

Agit rm .tmp

`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.

Bgit add -x .tmp *

`git add -x` is not a valid Git command for excluding specific file types during the staging process.

Cecho .tmp >> .gitignoreCorrect

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.

Drm -rf .tmp

`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

#Git#Version Control#.gitignore#File Exclusion

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice