npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

git-hook-prepush

v1.1.0

Published

Shared pre-push hook with build check and skip option

Readme

git-hook-prepush

A shared Git pre-push hook that runs a build check before allowing pushes to protected branches. Prevents broken builds from being pushed to important branches like dev, alpha-1, alpha-2, etc.

Installation

npm

npm install git-hook-prepush --save-dev

yarn

yarn add git-hook-prepush --dev

The hook is automatically installed during postinstall. It creates a .githooks/pre-push file and configures Git to use it.

How It Works

When you git push to a protected branch, the hook runs your build command. If the build fails, the push is blocked.

git push origin dev
# 🔨 Pre-push: Running build check for branch 'dev'...
# ✅ Build succeeded. Pushing...
git push origin dev
# 🔨 Pre-push: Running build check for branch 'dev'...
# ❌ Build failed. Push to 'dev' has been blocked.

Skip the build check

SKIP_BUILD=1 git push

Smart skip — only build if relevant files changed

Set SKIP_BUILD_IF_UNCHANGED to a space-separated list of paths. If none of those paths changed since the remote, the build is skipped automatically.

# Skip build if nothing in src/ or package.json changed
SKIP_BUILD_IF_UNCHANGED="src/ package.json" git push

You can also export it so it applies to every push:

export SKIP_BUILD_IF_UNCHANGED="src/ package.json tsconfig.json"

Configuration

Configuration is loaded in this order (highest priority first):

  1. Environment variables — set in shell or CI
  2. .githooksrc.json — project-level config file (commit this to share with your team)
  3. Defaults

Config file (recommended for teams)

Create a .githooksrc.json at your project root:

{
  "buildBranches": ["dev", "staging", "main"],
  "buildBranchPatterns": ["alpha-[0-9]+", "beta-[0-9]+", "release-.*"],
  "buildCmd": "npm run build",
  "skipBuildIfUnchanged": ["src/", "package.json", "tsconfig.json"]
}

A .githooksrc.example.json template is included in the package.

Environment variables

Add these to your .bashrc, .zshrc, or CI config (env vars override the config file):

BUILD_BRANCHES

Exact branch names that require a build check (space-separated).

Default: dev

export BUILD_BRANCHES="dev staging main"

BUILD_BRANCH_PATTERNS

Regex patterns for matching branch names (space-separated). Uses extended regex (grep -E).

Default: alpha-[0-9]+

export BUILD_BRANCH_PATTERNS="alpha-[0-9]+ beta-[0-9]+ release-.*"

This matches branches like alpha-1, alpha-2, beta-1, release-2.0, etc.

BUILD_CMD

The build command to run.

Default: npm run build

export BUILD_CMD="yarn build"

CLI Commands

npx git-hook-prepush             # Install the hook
npx git-hook-prepush --verify   # Check installation status + show config
npx git-hook-prepush --uninstall # Remove the hook
npx git-hook-prepush --help     # Show usage

Manual Setup

If the hook wasn't installed automatically, run:

# npm
npx git-hook-prepush

# yarn
yarn git-hook-prepush

Windows Support

This package uses a POSIX shell script for the git hook. On Windows, use one of:

Run all git push and npm install commands from Git Bash or WSL, not from CMD or PowerShell.

Uninstall

Remove the package and reset the Git hooks path:

# npm
npm uninstall git-hook-prepush

# yarn
yarn remove git-hook-prepush

# Reset Git hooks path
git config --unset core.hooksPath
rm -rf .githooks

License

MIT