Git hooks are scripts that run automatically on certain Git events (commit, push, etc).
Getting Started
What is Git?
Branching & Merging
Branches & Merging
Tags & Releases
Git Tags
Submodules & Subtree
Git Submodules
GitHub Actions
GitHub Actions CI/CD
Git Worktrees
Git Worktrees
Git LFS
Git LFS (Large Files)
Git
Beginner
FREE
Git Hooks
Lesson 1 of 17
Beginner
Interactive
Syntax
GIT
# .git/hooks/pre-commit #!/bin/sh npm test # .git/hooks/commit-msg #!/bin/sh # Check commit message format
Git Hooks
BASH
# .git/hooks/pre-commit #!/bin/sh # Run linting before commit npm run lint if [ $? -ne 0 ]; then echo "Linting failed. Commit aborted." exit 1 fi # Using husky (Node.js) # npm install husky --save-dev # npx husky install # npx husky add .husky/pre-commit "npm run lint"
Practice
1
Exercise
Practice this concept.
Answer
Run the commands as shown above.
Quick Quiz
1
What did you learn?
This covers the basics.
Interview Questions
It is a fundamental Git feature.