Three Approaches to Enforcing Consistent Commit Messages on GitHub
Which TWO approaches can you use to enforce consistent commit message conventions across your GitHub repositories?
Quick Answer
A repository ruleset that requires commit messages to match a defined pattern is the server-side way to enforce commit conventions — it rejects non-conforming pushes before they land, regardless of contributor. A GitHub Actions workflow that validates message format on push events is the complementary approach, catching violations even where rulesets alone might not apply.
⚠ Common exam trap
Many candidates confuse `.gitattributes` or branch naming with commit message enforcement, failing to recognize that only server-side rules or CI/CD actions can validate commit message content.
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
✓
Use a GitHub Action to validate commit messages on push
GitHub Actions can be configured with a workflow that triggers on `push` events to validate commit messages against a regex pattern, rejecting non-conforming commits. Option D is correct because repository rulesets (or branch protection rules) allow you to define required commit message patterns that must match before a push is accepted, enforced server-side. Both approaches enforce conventions consistently across all contributors.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Add a .gitattributes file
Why it's wrong here
.gitattributes handles file normalization, not commit messages.
- ✓
Use a GitHub Action to validate commit messages on push
Why this is correct
A custom action can check commit messages and reject non-conforming pushes.
- ✗
Set the default branch to main
Why it's wrong here
Default branch does not enforce commit message conventions.
- ✓
Create a repository rule that requires commit message patterns
Why this is correct
Repository rules can enforce commit message format.
- ✗
Set up an issue template
Why it's wrong here
Issue templates are for issues, not commits.
Go deeper
Related to this question
Learn chapter
Implementing Deployment Patterns and Strategies
Key term
Regex
Regex (regular expression) is a sequence of characters that defines a search pattern, used to match, find, or manipulate text in strings.
Key term
Branch
A branch is a pointer to a specific commit in a version control system that allows you to work on features or fixes in isolation from the main codebase.
About these practice questions
This AZ-400 question is part of Courseiva's 823-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on AZ-400
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. You want to ensure that every commit message in your repository follows a specific format. Which GitHub feature can enforce this?
easy- A.Webhooks to validate and reject pushes
- B.Branch protection rules
- C.GitHub Actions workflow with push trigger
- ✓ D.Required status checks with a commit lint action
Why D: Required status checks, when combined with a commit lint action in a GitHub Actions workflow, can enforce commit message formatting. The workflow runs on push or pull request events, and the status check must pass before a pull request can be merged, effectively rejecting commits that do not conform to the specified format.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-400 practice question is part of Courseiva's free Microsoft 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 AZ-400 exam.