Skip to content

Git Hooks

Git hooks are scripts that run automatically before or after Git events like commits, pushes, and merges. Axis provides a visual interface to manage and monitor hooks.

Understanding Hooks

Git hooks are stored in the .git/hooks directory of your repository. Common hooks include:

HookTriggerUse Case
pre-commitBefore commit is createdLint code, run tests
commit-msgAfter commit message is enteredValidate commit message format
pre-pushBefore push to remoteRun tests, check branch policies
post-mergeAfter merge completesInstall dependencies, rebuild
post-checkoutAfter checkout completesUpdate dependencies

Hook Status

When committing in Axis, hook execution is displayed in real-time:

  1. Running - Hook is currently executing
  2. Passed - Hook completed successfully
  3. Failed - Hook returned a non-zero exit code

WARNING

If a hook fails, the Git operation is aborted. Fix the issues reported by the hook and try again.

Bypassing Hooks

In some cases, you may need to skip hook execution:

  1. Open the commit dialog
  2. Enable Skip hooks option
  3. Proceed with your commit

DANGER

Only bypass hooks when absolutely necessary. Hooks exist to maintain code quality and consistency.

Common Hook Tools

Axis works seamlessly with popular hook managers:

Husky

Husky is a popular tool for managing Git hooks in JavaScript projects.

bash
# Install husky
npm install husky --save-dev

# Initialize
npx husky init

pre-commit

pre-commit is a framework for managing multi-language pre-commit hooks.

bash
# Install pre-commit
pip install pre-commit

# Install hooks
pre-commit install

lefthook

Lefthook is a fast and powerful Git hooks manager.

bash
brew install lefthook
lefthook install

Troubleshooting

Hook Not Running

  1. macOS/Linux: Ensure the hook file is executable: chmod +x .git/hooks/pre-commit
  2. Windows: Ensure Git can find the interpreter (bash, node, python, etc.)
  3. Check the shebang line at the top of the hook script (e.g., #!/bin/sh)
  4. Verify the hook is not disabled in Git config

Hook Timeout

Long-running hooks may appear to hang. Check:

  1. The hook script for infinite loops
  2. Network operations that may be slow
  3. Large file operations

Hook Output

Axis displays hook output in the commit dialog. For detailed debugging, run the hook manually:

bash
.git/hooks/pre-commit

Released under the MIT License.