# pre-commit/pre-commit-hooks

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/pre-commit-pre-commit-hooks).**

6,593 stars · 792 forks · Python · MIT

## Links

- GitHub: https://github.com/pre-commit/pre-commit-hooks
- awesome-repositories: https://awesome-repositories.com/repository/pre-commit-pre-commit-hooks.md

## Topics

`git` `linter` `pre-commit` `python` `refactoring`

## Description

This project is a comprehensive collection of pre-commit hooks designed to automate code linting, style enforcement, and file validation before changes are committed to version control. It provides a suite of ready-to-use scripts that serve as quality guards, including static analysis hooks, configuration file validators, and tools for maintaining version control integrity.

The collection distinguishes itself by offering specialized guards for repository health and security. This includes detection of leaked credentials and private keys, prevention of large file commits, and enforcement of branch protection to ensure a pull-request workflow. It also handles filesystem-specific issues such as OS-incompatible filenames, case-insensitive name conflicts, and the validation of symbolic links.

Broadly, the project covers automated code formatting to normalize whitespace, line endings, and quote styles, as well as syntax validation for Python, JSON, YAML, TOML, and XML. It further provides static analysis utilities to detect debugger statements, merge conflict markers, and incorrect test naming conventions.

## Tags

### Part of an Awesome List

- [Code Formatting and Linting](https://awesome-repositories.com/f/awesome-lists/devtools/code-formatting-and-linting.md) — Provides an automated suite of scripts for enforcing code style and linting standards before version control submission. ([source](https://github.com/pre-commit/pre-commit-hooks/blob/main/setup.py))
- [Code Formatting](https://awesome-repositories.com/f/awesome-lists/devtools/code-formatting.md) — Implements automated tools for enforcing consistent code formatting and style via pre-commit hooks.
- [Regex Pattern Matching](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching.md) — Uses regular expressions to identify prohibited patterns, sensitive secrets, or formatting inconsistencies in files.

### Development Tools & Productivity

- [Pre-commit Hooks](https://awesome-repositories.com/f/development-tools-productivity/pre-commit-hooks.md) — Provides a comprehensive collection of ready-to-use pre-commit hooks for automated linting and validation.
- [Configuration File Validators](https://awesome-repositories.com/f/development-tools-productivity/configuration-file-validators.md) — Provides automated verification of syntax and structure for project configuration files.
- [Coding Style Tools](https://awesome-repositories.com/f/development-tools-productivity/developer-utilities-libraries/developer-tools/code-quality-verification/coding-style-tools.md) — Ships scripts for normalizing line endings, trimming whitespace, and formatting structured data files.
- [Syntax and Type Verification](https://awesome-repositories.com/f/development-tools-productivity/developer-utilities-libraries/developer-tools/code-quality-verification/syntax-and-type-verification.md) — Verifies that Python files parse as valid code to prevent syntax errors in the repository. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [Git Repository Maintenance Tools](https://awesome-repositories.com/f/development-tools-productivity/git-repository-maintenance-tools.md) — Ensures repository health by detecting OS-incompatible filenames, broken symlinks, and oversized files.
- [Shell Orchestrators](https://awesome-repositories.com/f/development-tools-productivity/shell-orchestrators.md) — Orchestrates the execution of discrete script-based hooks and processes their exit codes to gate commits.
- [Automated Version Control Workflows](https://awesome-repositories.com/f/development-tools-productivity/automated-version-control-workflows.md) — Enforces quality standards and repository structure by blocking direct commits to protected branches.
- [Line Ending Standards](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/code-formatting-utilities/formatting-rules/line-ending-standards.md) — Standardizes mixed line endings and ensures every file ends with exactly one newline character. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [Quote Style Configurations](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines/static-analysis-tools/code-formatting-tools/quote-style-configurations.md) — Normalizes string quote styles by replacing double quotes with single quotes for consistency. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [JSON Formatting and Sorting](https://awesome-repositories.com/f/development-tools-productivity/json-formatting-and-sorting.md) — Pretty-prints JSON files with sorted keys and consistent indentation for improved readability. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [TOML Syntax Validators](https://awesome-repositories.com/f/development-tools-productivity/syntax-validation/toml-syntax-validators.md) — Provides automated syntax validation for TOML files to ensure structural correctness before commits. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [XML Syntax Validators](https://awesome-repositories.com/f/development-tools-productivity/syntax-validation/xml-syntax-validators.md) — Provides automated syntax validation for XML files to ensure structural correctness before commits. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [CI Conflict Detection](https://awesome-repositories.com/f/development-tools-productivity/version-control-repository-tools/version-control-managers/repository-utilities/automated-merge-conflict-resolvers/ci-conflict-detection.md) — Detects merge conflict markers in files to prevent unresolved conflicts from being committed. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [YAML Key Sorting](https://awesome-repositories.com/f/development-tools-productivity/yaml-key-sorting.md) — Sorts top-level keys in YAML files while preserving comments and block structures. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### DevOps & Infrastructure

- [Text Transformations](https://awesome-repositories.com/f/devops-infrastructure/configuration-management/file-based-configuration/file-attribute-modifiers/file-patchers/idempotent/text-transformations.md) — Implements a pipeline of idempotent rules for normalizing file contents across the codebase.
- [YAML Syntax Validation](https://awesome-repositories.com/f/devops-infrastructure/cicd-pipeline-automation/cicd-pipeline-management/ci-cd-workflows/ci-formatting-checks/yaml-syntax-validation.md) — Provides automated syntax validation for YAML files to ensure structural correctness before commits. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))
- [Branch Protections](https://awesome-repositories.com/f/devops-infrastructure/infrastructure/version-control-systems/branch-merging-strategies/branch-protections.md) — Blocks direct commits to specified branches to enforce a strict pull-request workflow. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### Programming Languages & Runtimes

- [Static Syntax Validation](https://awesome-repositories.com/f/programming-languages-runtimes/static-syntax-validation.md) — Automatically checks various file formats for syntax errors to prevent broken code from entering version control.
- [Whitespace Cleaners](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/language-syntax/whitespace-based-block-scoping/whitespace-cleaners.md) — Automatically removes trailing whitespace from the ends of lines while preserving specific markup. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### Security & Cryptography

- [Secret Detection Tools](https://awesome-repositories.com/f/security-cryptography/secret-detection-tools.md) — Provides automated scanning to detect leaked private keys and cloud credentials before they are committed to version control. ([source](https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md))
- [Secret Leak Prevention](https://awesome-repositories.com/f/security-cryptography/secret-leak-prevention.md) — Scans source code for private keys and cloud credentials to prevent accidental exposure of secrets.
- [Commit Blockers](https://awesome-repositories.com/f/security-cryptography/security/policies/host-resource-access/file-system-access-controls/sensitive-file-protections/commit-blockers.md) — Implements commit blocking to prevent files exceeding a specified size threshold from entering the repository. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### Software Engineering & Architecture

- [Syntax Validation](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing/syntax-validation.md) — Provides AST-based syntax validation to ensure code is grammatically correct before commits.
- [JSON Syntax Validators](https://awesome-repositories.com/f/software-engineering-architecture/json-schema-validation/json-syntax-validators.md) — Provides automated syntax validation for JSON files to ensure structural correctness before commits. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### Testing & Quality Assurance

- [Static Analysis](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis.md) — Implements automated checks to detect syntax errors, debugger statements, and secrets before commit.
- [Pre-Commit Quality Checks](https://awesome-repositories.com/f/testing-quality-assurance/testing-best-practices-methodologies/quality-assurance-practices/pre-commit-quality-checks.md) — Prevents large files, case conflicts, and broken symlinks from being committed via quality guards.
- [Debugger Statement Detection](https://awesome-repositories.com/f/testing-quality-assurance/debugger-statement-detection.md) — Scans source code for debugger imports and breakpoint calls to prevent shipping debug code. ([source](https://github.com/pre-commit/pre-commit-hooks#readme))

### System Administration & Monitoring

- [Filesystem Metadata Inspection](https://awesome-repositories.com/f/system-administration-monitoring/filesystem-metadata-inspection.md) — Inspects file permissions, symbolic links, and naming conventions to ensure cross-platform repository compatibility.
