All projects
Code★ 02026 ⎇ main GitHub ↗

krealalejo/lefthook-demo

lefthook-demo

POC for automating Git workflow enforcement with Lefthook — fast, cross-platform Git hooks manager.

What is this POC?

Demonstrates how to use Lefthook to enforce branch strategy, code quality, and versioning rules without relying on CI alone. All checks run locally, before code reaches the remote.

Setup

1. Install dependencies

yarn install

prepare script runs lefthook install automatically, registering all hooks.

2. Machine install (if needed)

lefthook install

Hooks

`pre-commit`

Hook Trigger Behavior
tests Every commit Runs yarn test — blocks commit on failure

`pre-push`

Hook Trigger Behavior
block-non-release-main-push Push to main Blocks push if HEAD is not a merge commit from a release/* or hotfix/* branch
tests-and-lint Push to main or develop Runs yarn test && yarn lint — blocks push on failure
release-summary-check Push to main Warns (non-blocking) if no commit starting with summary: exists in commits being pushed

`post-checkout`

Hook Trigger Behavior
bump-release-version Checkout to release/v* branch Auto-bumps package.json version to YY.MM.XX and commits it

Version bump logic (`YY.MM.XX`)

  • YY — 2-digit current year
  • MM — 2-digit current month (zero-padded)
  • XX — patch counter, zero-padded:
    • Same year + month as current version → XX + 1
    • Different year or month → resets to 00

Example: switching to release/v26.06 when current version is 26.06.02 → bumps to 26.06.03. Switching in a new month → 26.07.00.

Branch strategy enforced

gitGraph
   commit id: "..."
   branch develop
   checkout develop
   branch feature/foo
   checkout feature/foo
   commit id: "feat: foo"
   checkout develop
   merge feature/foo
   branch release/v26.06.00
   checkout release/v26.06.00
   commit id: "chore: upgrade to version v26.06.00" tag: "auto-bumped"
   commit id: "summary: release notes"
   checkout main
   merge release/v26.06.00
   branch hotfix/bar
   checkout hotfix/bar
   commit id: "fix: bar"
   checkout main
   merge hotfix/bar

Only release/* and hotfix/* merges are allowed into main. Direct pushes are blocked.