🌐
pre-commit
pre-commit.com
pre-commit
$ git init sample Initialized empty Git repository in /tmp/sample/.git/ $ cd sample $ git commit --allow-empty -m 'Initial commit' `.pre-commit-config.yaml` config file not found. Skipping `pre-commit`. [main (root-commit) d1b39c1] Initial commit · To still require opt-in, but prompt the user to set up pre-commit use a template hook as follows (for example in ~/.git-template/hooks/pre-commit).
🌐
GitHub
github.com › pre-commit › pre-commit › blob › main › .pre-commit-config.yaml
pre-commit/.pre-commit-config.yaml at main · pre-commit/pre-commit
- repo: https://github.com/pre-commit/pre-commit-hooks · rev: v6.0.0 · hooks: - id: trailing-whitespace · - id: end-of-file-fixer · - id: check-yaml · - id: debug-statements · - id: double-quote-string-fixer · - id: name-tests-test ·
Author   pre-commit
🌐
Stefanie Molin
stefaniemolin.com › articles › devx › pre-commit › setup-guide
How to Set Up Pre-Commit Hooks | Stefanie Molin
December 7, 2025 - Now that we have our .pre-commit-config.yaml file, we need to instruct Git to use our hooks. Every Git repository supports hooks at a variety of stages in the Git process. Hooks can be written in any language available on your the machine, and they must be placed in the .git/hooks directory to be triggered — pre-commit install does this for us. The executable that will run our pre-commit-stage hooks has been installed as .git/hooks/pre-commit: pre-commit-example ├── .git │ └── hooks │ ├── commit-msg.sample | ├── pre-commit | ├── pre-commit.sample | ├──
🌐
Xnok
xnok.github.io › infra-bootstrap-tools › docs › tools › pre-commit
Pre-commit: Your First Line of Defense for Clean Code · Infra Bootstrap Tools
2 weeks ago - Write Your Script: Create your script (e.g., a shell script, Python script) in your repository. For this example, let’s say you create my_custom_script.sh. Define in .pre-commit-config.yaml: Add a local hook entry to your configuration:
🌐
Apache
hamilton.apache.org › how-tos › pre-commit-hooks
pre-commit hooks - Hamilton - Apache Software Foundation
# .pre-commit-config.yaml repos: # repository with hook definitions - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 # release version of the repo hooks: # list of hooks from the repo to include in this project - id: end-of-file-fixer - id: trailing-whitespace - id: check-yaml args: ['--unsafe'] # some accept arguments # download another repository with hooks - repo: https://github.com/psf/black rev: 22.10.0 hooks: - id: black
🌐
GitHub
github.com › marick › pre-commit-hooks › blob › master › dot-pre-commit-config.yaml.sample
pre-commit-hooks/dot-pre-commit-config.yaml.sample at master · marick/pre-commit-hooks
stages: [commit, push] hooks: - id: only-branch-pushes · args: [prevent, ^(production|master)$] # You can prohibit just one branch with something like · # args: [prevent, production] · - id: prohibit-suspicious-patterns · # Arguments are Ruby regular expressions. # So, for example, you can prohibit "todo" with any case with: # "(?i-mx:TODO)" args: - AKIA[[:alnum:]]{14} # git commit ok - so this doesn't prevent itself.
Author   marick
🌐
GitHub
gist.github.com › julian-west › e50b25a9aa10551e3452f5a6cfaa6aa3
Example .pre-commit-config.yaml file · GitHub
Example .pre-commit-config.yaml file. GitHub Gist: instantly share code, notes, and snippets.
🌐
Engineering for Data Science
engineeringfordatascience.com › posts › improve code quality with git hooks and pre-commit
Improve Code Quality with Git Hooks and Pre-commit | Engineering for Data Science
February 24, 2022 - The configuration for pre-commit hooks are defined in a .pre-commit-config.yaml file. Instructions on how to format the file are described in the documentation . A very simple configuration file could look something like this: # example .pre-commit-config.yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.3.0 hooks: - id: check-yaml - id: requirements-txt-fixer - id: trailing-whitespace
🌐
Poetry
python-poetry.org › docs › pre-commit-hooks
pre-commit hooks | Documentation | Poetry - Python dependency management and packaging made easy
A .pre-commit-config.yaml example for a monorepo setup or if the pyproject.toml file is not in the root directory:
Find elsewhere
Top answer
1 of 2
4

there is intentionally no such "include" mechanism for pre-commit configurations.

each repository tends to have some customization needed (on top of a theoretical "base" configuration) and as such an include mechanism would tend to reduce flexibility instead of increasing convenience.

pre-commit already provides reusable repositories which is where the bulk of the complexity lies

there are hacky workarounds some have come up with in the issue tracker (such as utilizing a hook which itself calls pre-commit --config ... in a nested manner) but these are not encouraged


disclaimer: I wrote pre-commit

2 of 2
0

If I correctly understand your question, you need to create a .pre-commit-config.yaml file in each repository where you want to use this pre-commit configuration.

The file should look like this:

repos:
 - repo: https://github.com/gruntwork-io/pre-commit
    rev: v0.1.17
    hooks:
      - id: terraform-fmt
  • repo should point to your repository containing the pre-commit hooks;

  • rev specifies the version. You can use a Git tag, or a specific Git commit hash;

  • hooks:id this is an id (like name) of specific hook within your repository;

You can find all available parameters in the documentation

And here’s an example repository: https://github.com/gruntwork-io/pre-commit

And of course in each repo you need to do the following:

  • Install pre-commit. E.g. brew install pre-commit.
  • Run pre-commit install in the repo.

Alternatively, instead of using pre-commit, you might find it more suitable to use a Git template along with Git hooks, such as prepare-commit-msg. In that case you can check my repo with examples, which could serve as a good starting point.

The only downside is that you'll need to set the environment variable GIT_TEMPLATE_DIR which point to git-template, and run git int command every time after you updated git-template repo.

🌐
Madewithml
madewithml.com › courses › mlops › pre-commit
Pre-commit - Made With ML by Anyscale
Besides pre-commit's built-in hooks, there are also many custom, 3rd party popular hooks that we can choose from. For example, if we want to apply formatting checks with Black as a hook, we can leverage Black's pre-commit hook.
🌐
GitHub
github.com › pre-commit › pre-commit-hooks › blob › main › .pre-commit-hooks.yaml
pre-commit-hooks/.pre-commit-hooks.yaml at main · pre-commit/pre-commit-hooks
description: sorts the lines in specified files (defaults to alphabetical). you must provide list of target files as input in your .pre-commit-config.yaml file.
Author   pre-commit
🌐
GitHub
github.com › readthedocs › common › blob › main › pre-commit-config.yaml
common/pre-commit-config.yaml at main · readthedocs/common
- repo: https://github.com/pre-commit/pre-commit-hooks · rev: v5.0.0 · hooks: # Disabled because yapf is better for our purpose · # - id: autopep8-wrapper · - id: check-added-large-files · - id: check-ast · - id: check-case-conflict ·
Author   readthedocs
🌐
Dagworks
blog.dagworks.io › p › custom-pre-commit-hooks-for-safer
Custom pre-commit hooks for safer code changes
April 2, 2024 - Add a .pre-commit-config.yaml to your repository. Here’s an example:
🌐
Medium
medium.com › @jay.gokani › pre-commit-hooks-39bb1668dc95
Pre-commit Hooks. In the fast-paced world of software… | by DevOps Snapshots | Medium
October 26, 2023 - Here's an example configuration: # .pre-commit-config.yaml # use github's pre-commit-hooks library to detect issues repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.1.0 hooks: - id: trailing-whitespace
🌐
Gitlab
gdevops.gitlab.io › tuto_git › tools › pre-commit › examples › examples.html
pre-commit examples — Tuto git
July 29, 2023 - Sign in to GitLab · Loading · By signing in you accept the Terms of Use and acknowledge the Privacy Statement and Cookie Policy · Don't have an account yet? Register now · or sign in with · Remember me · Explore Help About GitLab GitLab community forum