How can I manually run a Git pre-commit hook, without attempting a commit?

I just want to be able to run it to see if the code in my working tree passes it, without actually attempting a commit.


Just run the pre-commit script through the shell:

bash .git/hooks/pre-commit

There's a Python package for this available here. Per the usage documentation:

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files. To run individual hooks use pre-commit run <hook_id>.

So pre-commit run --all-files is what the OP is after.


Just run git commit. You don't have to add anything before doing this, hence in the end you get the message no changes added to commit.


For a single file:

pre-commit run --files YOUR_FILENAME