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:
| Hook | Trigger | Use Case |
|---|---|---|
pre-commit | Before commit is created | Lint code, run tests |
commit-msg | After commit message is entered | Validate commit message format |
pre-push | Before push to remote | Run tests, check branch policies |
post-merge | After merge completes | Install dependencies, rebuild |
post-checkout | After checkout completes | Update dependencies |
Hook Status
When committing in Axis, hook execution is displayed in real-time:
- Running - Hook is currently executing
- Passed - Hook completed successfully
- 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:
- Open the commit dialog
- Enable Skip hooks option
- 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.
# Install husky
npm install husky --save-dev
# Initialize
npx husky initpre-commit
pre-commit is a framework for managing multi-language pre-commit hooks.
# Install pre-commit
pip install pre-commit
# Install hooks
pre-commit installlefthook
Lefthook is a fast and powerful Git hooks manager.
brew install lefthook
lefthook installTroubleshooting
Hook Not Running
- macOS/Linux: Ensure the hook file is executable:
chmod +x .git/hooks/pre-commit - Windows: Ensure Git can find the interpreter (bash, node, python, etc.)
- Check the shebang line at the top of the hook script (e.g.,
#!/bin/sh) - Verify the hook is not disabled in Git config
Hook Timeout
Long-running hooks may appear to hang. Check:
- The hook script for infinite loops
- Network operations that may be slow
- Large file operations
Hook Output
Axis displays hook output in the commit dialog. For detailed debugging, run the hook manually:
.git/hooks/pre-commit