CompTIA Linux+ (XK0-006)Automation, Orchestration and ScriptingEasy

A DevOps engineer is setting up a Git repository for a new project. They want to ensure that all developers use a consistent code style and that certain linting checks are performed automatically before any commit is finalized. Which Git feature should the engineer configure to enforce these checks?

  1. AGit hooks
  2. BGit aliases
  3. CGit submodules
  4. DGit LFS
Show answer & explanation

Correct answer: A. Git hooks

Git hooks are scripts that Git executes automatically before or after events like commit, push, or receive. A `pre-commit` hook, for instance, can be used to run linters, formatters, or other checks on the staged changes, preventing commits that don't meet specified criteria.

Why the other options are wrong

  • B. Git aliases are shortcuts for Git commands, not for enforcing pre-commit checks.
  • C. Git submodules are used for embedding one Git repository inside another, unrelated to code style enforcement.
  • D. Git LFS (Large File Storage) is for managing large files in Git, not for code quality checks.

Git Hooks

Git hooks are scripts that Git executes automatically before or after events such as commit, push, and receive. They can be used to automate tasks, enforce policies, and integrate with continuous integration systems.

  • Scripts located in the `.git/hooks` directory.
  • Examples include `pre-commit`, `post-commit`, `pre-push`, `post-receive`.
  • Can be used for linting, testing, formatting, and deployment tasks.

Memory trick: Hooks control the flow, ensuring rules are met.

More Automation, Orchestration and Scripting questions