Git hooks for monorepos. You can put a config file in any directory. Its hooks run only on the files in that directory.
tree-commit reads the same config file format as pre-commit and runs the same hooks. The difference is that you can have one config file per directory, not one config file for the full repository:
my-repo/
├── .tree-commit-config.yaml ← whitespace, YAML and spelling checks for everything
├── backend/
│ ├── .tree-commit-config.yaml ← ruff and pytest, only for backend/ files
│ └── app.py
└── frontend/
├── .tree-commit-config.yaml ← eslint and prettier, only for frontend/ files
└── src/App.tsx
If you change backend/app.py and commit, the root hooks and the backend hooks run. The frontend hooks do not run.
You need Go 1.23 or newer and git.
Run this command to install tree-commit:
go install github.com/danielsada/tree-commit@latestRun this command to make sure that tree-commit works:
tree-commit --version1. Add a config file to any directory. This example is for a Python project. It uses uv to run ruff, so you do not have to install ruff:
# backend/.tree-commit-config.yaml
repos:
- repo: local
hooks:
- id: ruff-check
name: ruff check
entry: uvx ruff check --fix
language: system
types: [python]
- id: pytest
name: pytest
entry: uv run pytest -q # runs inside backend/
language: system
types: [python]
pass_filenames: false2. Install the git hook in your repository:
tree-commit install3. Commit your changes as usual. tree-commit checks the files that you staged:
$ git commit -m "Add the orders endpoint"
ruff check (backend/)....................................................Failed
- hook id: ruff-check
- exit code: 1
F821 Undefined name `order`
--> app.py:2:41
|
1 | def total(orders):
2 | return sum(order.price for order in order)
| ^^^^^
Found 1 error.
pytest (backend/)........................................................Passed
trim trailing whitespace.................................................PassedIf a hook fails, or if a hook fixes a file, the commit stops. Then do these steps:
- Read the output.
- Use
git addto stage the fixes. - Commit again.
These are the commands that you use most frequently:
tree-commit run # check staged files, like the git hook does
tree-commit run --all-files # check all files in the repository
tree-commit run ruff-check # run one hook only
tree-commit run --dry-run # list the hooks to run, but do not run them
tree-commit tree # show where your config files are
SKIP=pytest git commit # skip a hook one time
tree-commit baseline # accept the current violations of grep hooks
tree-commit uninstall # remove the git hookYou do not have to change your .pre-commit-config.yaml file. If a directory has no .tree-commit-config.yaml, tree-commit reads the .pre-commit-config.yaml in that directory. tree-commit downloads and runs hooks from hook repositories such as pre-commit-hooks and ruff-pre-commit. For more information, see Migrating from pre-commit.
These pages give more information:
- Getting started: a full walkthrough
- Configuration: all config file options
- How it works: nested config files, overrides, order of execution and parallel execution
- Hooks and languages: local hooks, remote hook repositories, Python
- Command line: commands, flags and environment variables
- Recipes: monorepo patterns, CI, uv and ruff, Go
- Migrating from pre-commit
- Troubleshooting
The example monorepo shows all features in a realistic configuration.
See Development.
tree-commit is available under the MIT license. See LICENSE.