no-push-oops
v1.0.10
Published
A Git pre-push hook that runs your preflight checks to prevent oops moments
Maintainers
Readme
no-push-oops
Prevent "oops" moments by running preflight checks before every Git push
A lightweight, configurable Git pre-push hook that automatically runs your quality checks (tests, linting, type-checking, etc.) before allowing a push to go through.
Features
- Zero Configuration - Works out of the box with sensible defaults
- Highly Configurable - Customize commands, messages, and behavior
- Auto-Installation - Automatically sets up Git hooks on install
- Beautiful Output - Color-coded, clean terminal output
- Timeout Support - Prevent hung processes
- Branch-Specific - Skip checks on specific branches
- CI-Aware - Automatically skips in CI environments
- TypeScript Support - Fully typed for better DX
Installation
npm install --save-dev no-push-oopsOr with yarn:
yarn add -D no-push-oopsOr with pnpm:
pnpm add -D no-push-oopsManual Hook Installation
If the hook isn't installed automatically:
npx no-push-oops installQuick Start
- Install the package:
npm install --save-dev no-push-oops- Add configuration to your
package.json:
{
"no-push-oops": {
"command": "npm run pr-preflight"
},
"scripts": {
"pr-preflight": "npm run lint && npm run test && npm run build"
}
}- That's it! Now every time you push, your preflight checks will run automatically.
Configuration
Configuration File
You can configure no-push-oops in three ways:
- In
package.json:
{
"no-push-oops": {
"command": "npm run pr-preflight",
"message": "Running quality checks...",
"skipCI": true,
"skipOnBranches": ["main", "develop"],
"verbose": false,
"timeout": 300000
}
}- In
.nopushoopsrc.json:
{
"command": "npm run pr-preflight",
"message": "Running quality checks...",
"skipCI": true
}- In
.nopushoopsrc:
{
"command": "npm run pr-preflight"
}Configuration Options
| Option | Type | Default | Description |
| ---------------- | ---------- | ------------------------------------------- | ------------------------------------ |
| command | string | "npm run pr-preflight" | Single command to run |
| commands | string[] | - | Multiple commands to run in sequence |
| message | string | "Running pr-preflight checks before push" | Custom message to display |
| skipCI | boolean | true | Skip checks in CI environments |
| skipOnBranches | string[] | [] | Branches to skip checks on |
| verbose | boolean | false | Show detailed output |
| timeout | number | 300000 | Command timeout in milliseconds |
Multiple Commands
You can run multiple commands in sequence:
{
"no-push-oops": {
"commands": ["npm run lint", "npm run test", "npm run type-check", "npm run build"]
}
}Usage
Automatic (Recommended)
Once installed, no-push-oops will automatically run on every git push. If the checks fail, the push will be aborted.
Manual Run
You can manually run the checks:
npx no-push-oops runBypass Hook (Emergency Only)
If you need to bypass the hook (not recommended):
git push --no-verifyUninstall
To remove the hook:
npx no-push-oops uninstallCommon Use Cases
Basic Linting and Testing
{
"no-push-oops": {
"command": "npm run lint && npm run test"
}
}Full CI Pipeline
{
"no-push-oops": {
"commands": [
"npm run lint",
"npm run test:unit",
"npm run test:integration",
"npm run type-check",
"npm run build"
],
"message": "Running full CI pipeline...",
"timeout": 600000
}
}Skip on Main Branch
{
"no-push-oops": {
"command": "npm run validate",
"skipOnBranches": ["main", "master", "production"]
}
}Verbose Mode for Debugging
{
"no-push-oops": {
"command": "npm run test",
"verbose": true
}
}CLI Commands
# Install the pre-push hook
npx no-push-oops install
# Uninstall the pre-push hook
npx no-push-oops uninstall
# Run checks manually
npx no-push-oops run
# Show help
npx no-push-oops helpWhy no-push-oops?
Problem: You push code, CI fails, you fix it, push again, repeat...
Solution: Run your CI checks locally before pushing. Catch issues early!
Benefits:
- Catch issues before pushing - Save time and embarrassment
- Faster feedback - Know immediately if something's wrong
- Better Git history - No "fix CI" commits
- Team consistency - Everyone runs the same checks
- Easy to set up - One npm install and you're done
Comparison with Other Tools
| Feature | no-push-oops | husky | pre-commit | | ---------------- | ------------ | ----- | ---------- | | Zero config | Yes | No | No | | TypeScript | Yes | No | No | | Pre-push focus | Yes | No | No | | Auto-install | Yes | Yes | Yes | | Branch filtering | Yes | No | Yes | | Timeout support | Yes | No | Yes |
Example Projects
Check out these example configurations:
TypeScript/React Project
{
"scripts": {
"pr-preflight": "npm run lint && npm run type-check && npm run test && npm run build"
},
"no-push-oops": {
"command": "npm run pr-preflight",
"skipOnBranches": ["main"]
}
}Node.js API
{
"scripts": {
"pr-preflight": "npm run lint && npm run test:coverage && npm run build"
},
"no-push-oops": {
"commands": [
"npm run lint",
"npm run test:coverage",
"npm run security-check",
"npm run build"
],
"timeout": 600000
}
}Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT © Sheikh
FAQ
Q: What if I need to push urgently and checks are failing?
A: Use git push --no-verify to bypass the hook. But use this sparingly!
Q: Can I run different checks on different branches?
A: Not directly, but you can skip checks on certain branches and implement branch logic in your scripts.
Q: Does this work with GitLab/GitHub/Bitbucket?
A: Yes! It works with any Git repository.
Q: What if the hook isn't running?
A: Run npx no-push-oops install manually to reinstall the hook.
Q: Can I use this in a monorepo?
A: Yes! Install it at the root and configure commands accordingly.
Made to prevent oops moments
