hardMultiple Choice
XK0-006 Practice Question: A DevOps team wants to automatically run tests…
A DevOps team wants to automatically run tests before every commit in a local Git repository. Which Git hook should be used?
⚠ Common exam trap
Many exam-takers confuse the timing of Git hooks: candidates often pick pre-push because they think of 'testing before pushing,' but the question explicitly asks about 'before every commit,' which requires the pre-commit hook.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
pre-commit
The pre-commit hook runs before a commit is created, making it the correct choice for automatically running tests before every commit in a local Git repository. This hook can validate code quality, run unit tests, or check for syntax errors, and if it exits with a non-zero status, the commit is aborted.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
post-receive
Why it's wrong here
post-receive runs on the receiving repository after a push arrives, so it cannot intercept a local commit before it is created. It suits server-side deployment or notification automation, not pre-commit testing in a developer's working repository.
- ✓
pre-commit
Why this is correct
The pre-commit hook executes client-side immediately before Git finalises a commit, so tests run against staged content and can abort the commit on failure. This satisfies the stem's requirement of running tests before every commit in a local repository.
- ✗
post-commit
Why it's wrong here
A post-commit hook fires after the commit object is already created, so it cannot block or validate the commit — tests would run too late to prevent it. It suits notifications, logging or triggering CI after a successful commit. Pre-commit is the hook that runs before the commit is finalised, allowing tests to gate it.
- ✗
pre-push
Why it's wrong here
pre-push runs before objects transfer to a remote, so a local commit has already been created and tests cannot prevent it. It suits blocking pushes that fail checks; pre-commit is the hook that gates commit creation itself.
Go deeper
Related to this question
About these practice questions
Courseiva writes every XK0-006 question from scratch — 781 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.