This guide helps you set up local secret scanning and code quality checks to prevent accidental commits of secrets and other issues.
macOS/Linux:
brew install pre-commit
# or
pip install pre-commitWindows (PowerShell):
pip install pre-commitFrom the project root:
pre-commit installThis installs git hooks that automatically run before each commit.
# Scan all files
pre-commit run --all-files
# Scan specific file types
pre-commit run ggshield --all-files
# Run just before committing
pre-commit runThe pre-commit hooks check for:
- ggshield - Detects secrets using GitGuardian rules
- detect-private-key - Detects SSH keys, PGP keys, etc.
- detect-aws-credentials - Detects AWS access keys
- Trailing whitespace - Removes extra spaces
- End-of-file-fixer - Ensures files end with newline
- YAML validator - Checks YAML syntax
- JSON validator - Checks JSON syntax
- Large files - Prevents commits of files > 1MB
- ESLint - TypeScript/JavaScript linting
Pre-commit configuration is in .pre-commit-config.yaml.
Keep hooks up to date:
# Show outdated hooks
pre-commit autoupdate
# Then commit the updated `.pre-commit-config.yaml`The first run may take time downloading dependencies. Subsequent runs are faster.
# Speed up by pre-caching
pre-commit install-hooksOnly in emergencies:
git commit --no-verifypre-commit cleanggshield Issues:
# Install ggshield
pip install ggshield
# Verify it works
ggshield secret scan repo .
# Check API key
ggshield auth statusESLint Issues:
# Reinstall dependencies
rm -rf node_modules
pnpm install# Run all pre-commit hooks
pre-commit run --all-files
# Run specific hook
pre-commit run ggshield --all-files
# Uninstall hooks
pre-commit uninstall
# Reinstall hooks
pre-commit install
# Get hook info
pre-commit info-hooks
# Show hook stages
pre-commit config
# Skip hooks for this commit only
SKIP=ggshield git commit -m "message"ggshield needs access to GitGuardian's API for advanced scanning:
- Go to GitGuardian Dashboard
- Settings → API keys
- Create a new personal API key (copy it)
Option A: Environment Variable
export GITGUARDIAN_API_KEY="your-api-key-here"Option B: Config File
# macOS/Linux
mkdir -p ~/.config/ggshield
cat > ~/.config/ggshield/config.yaml << EOF
gitguardian:
api_key: "your-api-key-here"
EOF
# Windows
mkdir %USERPROFILE%\.ggshield
# Create config.yaml with your API keyOption C: Prompt on First Use
ggshield auth configureggshield auth status
ggshield secret scan repo .# Clone
git clone https://github.com/sublime247/mobile-money.git
cd mobile-money
# Install pre-commit
pre-commit install
# Install project dependencies
pnpm install
# Now commits are protected!In GitHub:
- Settings → Secrets and variables → Actions
- Add
GITGUARDIAN_API_KEYsecret
This enables GitGuardian scanning in CI/CD pipelines.
After setup, verify everything works:
# 1. Verify git hooks installed
ls -la .git/hooks/ | grep pre-commit
# 2. Test by trying to commit a fake secret
echo "password123abc = 'super_secret_key'" > test_secret.ts
git add test_secret.ts
git commit -m "Test" # This should fail
# 3. Remove test file
rm test_secret.ts
git reset --hard- First run takes time - Downloading tools and dependencies for the first time
- Keep API key safe - Treat like password, never commit it
- Update regularly - Run
pre-commit autoupdatemonthly - Check logs - If hook fails, read the output carefully
- Ask questions - If setup issues, ask the team!
Remember: Pre-commit hooks protect YOU and the team! ✨