Manually Run Git Hooks

04-01-2022

Sometimes you want to manually run a Git hook, like a pre-commit hook, for testing. This can be done from the shell.

  1. Navigate to the directory containing your Git repository

    1
    cd /path/to/code

    Example directory:

    |- .git
    |— hooks
    |—– pre-commit
    |- src
    |— file.js
    |- READEME.md

  2. Run hook using your shell

    1
    2
    3
    4
    bash <path to hook>

    # Ex:
    bash .git/hooks/pre-commit