| name | install-git-hooks |
| description | Install pre-commit hooks to automatically lint markdown files before commits |
| group | git |
| author | @tnez |
| version | 1.0.0 |
| keywords | ["git","hooks","automation","linting"] |
Runbook: Install Git Hooks
Purpose: Install pre-commit hooks to automatically lint markdown files before commits
Owner: Development Team
Last Updated: 2025-10-20
Frequency: One-time setup per developer environment
Overview
This runbook provides the procedure for installing git hooks in your local docent repository. Git hooks automatically run quality checks before committing, helping catch markdown linting errors early in the development process.
Script Reference: ../../scripts/install-git-hooks.sh
Expected duration: 1-2 minutes
What this accomplishes:
- Installs pre-commit hook that runs markdown linting on staged
.md files
- Prevents commits with markdown linting errors
- Provides early feedback before CI/CD runs
Note: This is optional but recommended for all developers.
Prerequisites
Required Tools
git - Version control system
npm - Node.js package manager
- Project dependencies installed (
npm install)
Required Access
- Write access to local
.git/hooks directory (standard for any git repository)
Pre-Flight Checklist
Before starting, ensure:
Procedure
Step 1: Verify Location
Purpose: Ensure you're in the correct directory
Commands:
pwd
ls -d .git
ls -d .git/hooks
Validation:
- You're in the project root
.git directory exists
.git/hooks directory exists
If step fails:
- Navigate to project root:
cd /path/to/docent
- If
.git doesn't exist: git init or clone the repository again
Step 2: Run Installation Script
Purpose: Install the pre-commit hook
Commands:
scripts/install-git-hooks.sh
Validation:
- Script completes successfully with ✓ message
- No error messages displayed
- Exit code is 0
If step fails:
-
Error: "Not in a git repository root directory"
- Navigate to project root and retry
- Verify
.git directory exists
-
Error: "Permission denied"
- Check file permissions:
ls -l scripts/install-git-hooks.sh
- Make executable if needed:
chmod +x scripts/install-git-hooks.sh
-
Error: "No such file or directory"
- Verify hook source exists:
ls scripts/hooks/pre-commit
- Pull latest changes from repository
Step 3: Verify Hook Installation
Purpose: Confirm the hook is properly installed and executable
Commands:
ls -l .git/hooks/pre-commit
head -5 .git/hooks/pre-commit
Validation:
- File
.git/hooks/pre-commit exists
- File is executable (permissions include
x)
- File contains shell script code
If step fails:
- Hook file missing: Re-run installation script
- Not executable:
chmod +x .git/hooks/pre-commit
Step 4: Test Hook
Purpose: Verify the hook runs on commit
Commands:
echo "# Test" > test-lint.md
echo "No blank line before list:" >> test-lint.md
echo "- item 1" >> test-lint.md
git add test-lint.md
git commit -m "test: verify pre-commit hook"
git reset HEAD test-lint.md
rm test-lint.md
Validation:
- Hook runs when you attempt to commit
- You see markdown linting output
- Commit is blocked if there are linting errors (expected behavior)
If step fails:
- Hook doesn't run: Verify installation in Step 3
- Hook runs but always passes: Check hook script contents
- Permission errors: Verify hook is executable
Validation
After completing all steps, verify:
-
Hook Installed:
ls -l .git/hooks/pre-commit
-
Hook Runs on Commit:
- Create and stage a markdown file
- Run
git commit
- Observe hook output
-
Can Bypass if Needed:
git commit --no-verify -m "test"
git reset HEAD~1
Uninstall
If you need to remove the git hooks:
Remove Pre-Commit Hook
rm .git/hooks/pre-commit
ls .git/hooks/pre-commit
When to uninstall:
- You prefer to run linting manually
- Hook is causing issues
- Switching to a different linting workflow
Note: You can always reinstall by running the installation script again.
Troubleshooting
Common Issues
Issue 1: Hook Blocks All Commits
Symptoms:
- Every commit attempt is blocked
- Linting errors on files you didn't change
Resolution:
npm run lint:md
scripts/lint-markdown.sh --fix
git commit --no-verify -m "message"
Issue 2: Hook Doesn't Run
Symptoms:
- Commits succeed without any hook output
- No linting checks performed
Resolution:
ls -l .git/hooks/pre-commit
scripts/install-git-hooks.sh
chmod +x .git/hooks/pre-commit
git commit --dry-run -m "test"
Issue 3: markdownlint-cli2 Not Found
Symptoms:
- Hook runs but fails with "command not found"
- Error about missing markdownlint-cli2
Resolution:
npm install
npx markdownlint-cli2 --version
cat .git/hooks/pre-commit
When to Escalate
Escalate if:
- Hook installation script fails consistently
- Hook causes git to hang or crash
- Hook blocks valid commits repeatedly
- Need to modify hook behavior
Escalation Contact:
- Repository maintainer
- Development team lead
Post-Procedure
After installation:
Quick Reference
Essential Commands
scripts/install-git-hooks.sh
ls -l .git/hooks/pre-commit
git commit --no-verify -m "message"
rm .git/hooks/pre-commit
npm run lint:md
scripts/lint-markdown.sh
Notes
Important Notes:
- Hook is local to your repository - not committed or shared via git
- Each developer must install hooks separately
- Hook only runs on
git commit, not on git push or other commands
- Bypassing with
--no-verify should be rare - prefer fixing linting errors
Gotchas:
- Hook only lints staged markdown files, not all files
- If you have unstaged changes in markdown files, those won't be linted
- Journal files in
docs/.journal/ are gitignored and won't be linted
- Hook runs before commit message editor opens
Related Procedures:
Revision History
| Date | Author | Changes |
|---|
| 2025-10-20 | @tnez | Initial creation |