Field Note

Custom local pre-commit hooks

pre-commit git hooks
Posted on Friday, July the 19th 2024
1 min read

Pre-commit is a framework that allows to easily run Git pre-commit hooks on staged files before they are committed. There are a variety of standard pre-commit hooks as well as community hooks (see supported hooks).

Pre-commit is extendable. One of the easiest ways to add another hook is to use the pseudo repository local and run a shell script.

Let’s assume, for example, we want to simply see the staged set, we can do this by adding the following to Pre-commit’s configuration file .pre-commit-config.yaml:

repos:
    # ...
    - repo: local
      hooks:
        - id: ls
          name: List the staged files
          entry: ls 
          language: system
          pass_filenames: true

Now, running pre-commit run -v ls will give us the set of staged files.

friedrichkurz.me

© 2025 Friedrich Kurz

Privacy Policy