QA
Intermediate LevelGit & GitHub

How do Git Hooks and Husky automate code linting and formatting before commits?

❓ Interview Prompt: Explain client-side Git hooks (.git/hooks/), pre-commit / pre-push hooks, and managing hooks with Husky & lint-staged in Node.js.

Git Hooks are shell scripts in .git/hooks/ executed during Git events. Husky shares hooks across teams via package.json, and lint-staged runs linters (ESLint, Prettier) strictly on staged files before allowing commits.

Code Implementation Example

json
{
  "scripts": { "prepare": "husky install" },
  "lint-staged": { "*.{js,ts}": ["eslint --fix", "prettier --write"] }
}
💡Configuring Husky and lint-staged for automated pre-commit linting.
🎯 Interview Key Takeaway

Use Husky and lint-staged to run linters automatically on pre-commit hooks, enforcing code standards before commits enter history.

#Git Hooks#Husky#lint-staged#Intermediate
Back to all Git & GitHub Questions→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?