🪝
Security

pre-commit

Git hooks that run linters and security checks before commit

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

pre-commit installs Git hooks that run linters and formatters before each commit.

📁

Config files for pre-commit

Where to create or edit the main configuration — paths below match the setup steps.

  • .pre-commit-config.yaml

    Location: Repository root

    Hooks — linters, formatters before commit

📥

Step 01

Install pre-commit

(01)Install pre-commit

Linux
1pip install pre-commit
2# Or: sudo apt-get install pre-commit
⚙️

Step 02

Configure pre-commit

(01)Configure pre-commit

Linux
1cat > .pre-commit-config.yaml << 'EOF'
2repos:
3 - repo: https://github.com/pre-commit/pre-commit-hooks
4 rev: v4.6.0
5 hooks:
6 - id: trailing-whitespace
7 - id: check-yaml
8EOF
9pre-commit install

Step 03

Verify

(01)Verify installation

Linux
1pre-commit run --all-files