⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Git & Branching Workflows Interview Questions Scenario 26 of 52 in Git & Branching Workflows
Senior DevOps / SRE [L2] Git From your main checkout (on feature/new-api): Production Scenario [L2]
🎯 Target Role / Context: Git Scenario #26 (L2) · From your main checkout (on feature/new-api):

Q: Your team wants to enforce coding standards and prevent certain mistakes at commit time — for example, blocking commits with `console.log()` or failing if unit tests don't pass. How would you set this up with Git hooks?

Git hooks are scripts that run at specific points in the Git workflow. For pre-commit enforcement:

#Git #L2 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""When an engineer accidentally creates this branch or commit divergence, I walk them through safe recovery without data loss. The interviewer is testing: Understanding of Git hooks, client-side vs server-side, and tooling like Husky.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: "When an engineer accidentally creates this branch or commit divergence, I walk them through safe recovery without data loss. The interviewer is testing: Understanding of Git hooks, client-side vs server-side, and tooling like Husky.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."

1️⃣

Initial Diagnostics & Root Cause Analysis

Git hooks are scripts that run at specific points in the Git workflow. For pre-commit enforcement:

  • pre-commit hook — runs before the commit is created. Exit non-zero to block the commit:
  • commit-msg hook — validates the commit message format (e.g., enforce Conventional Commits or JIRA ticket references):
  • pre-push hook — run tests before allowing a push.
  • Husky (Node.js) — stores hooks in .husky/ in the repo and installs them via npm prepare.
2️⃣

Remediation & Permanent Safeguards

The distribution problem: hooks live in .git/hooks/, which is not committed to the repo. Solutions: Client-side hooks can be bypassed with git commit --no-verify. For enforcement you can't skip, use server-side hooks (pre-receive, update) on the Git server, or platform-based checks (GitHub required status checks, GitLab push rules).

#!/bin/sh
   # .git/hooks/pre-commit
   if git diff --cached --name-only | xargs grep -l 'console.log'; then
     echo "ERROR: Remove console.log() before committing"
     exit 1
   fi
  • pre-commit framework (Python) — .pre-commit-config.yaml defines hooks from shared repos.
  • lefthook (Go) — similar, language-agnostic, fast.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: pre-commit hook — runs before the commit is created. Exit non-zero to block the commit:."
⚡ 60-Second Elevator Pitch Talking Points
  • pre-commit hook — runs before the commit is created. Exit non-zero to block the commit:
  • commit-msg hook — validates the commit message format (e.g., enforce Conventional Commits or JIRA...
  • pre-push hook — run tests before allowing a push.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring team wants enforce git push --force unconditionally overwrites remote commits made by teammates, whereas --force-with-lease aborts if the remote ref was updated.
  2. Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring team wants enforce Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
  3. Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring team wants enforce git reflog tracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches.
  4. Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring team wants enforce Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.
Advertisement
Want more Git & Branching Workflows scenarios?
Explore our complete collection of scenario-based Git & Branching Workflows interview runbooks.
Browse All Git & Branching Workflows Questions →