By default unit tests run in watch mode. You can override this by doing ng test --watch=false

Answer from Dimitar Cetelev on Stack Overflow
🌐
Medium
medium.com › @rifaly1100 › how-to-integrate-husky-pre-commit-and-pre-push-rules-in-your-project-prettier-and-eslint-a-75454ff5783c
How to integrate husky pre-commit and pre-push rules in your project( Prettier and Eslint) A Step-by-Step Guide | by Riffat Aly | Medium
November 4, 2023 - In your project’s package.json file, add a husky section with hooks for pre-commit and pre-push hooks. These hooks will execute specified scripts before a commit or push. Here's an example:
Discussions

Setup pre-push hook with Husky to prevent pushing to master branch
This script will block anybody ... branch. For example you are in branch fix/someissue but then you mistakenly type git push origin master. For more detailed instructions you can follow from this article: https://github.com/talenavi/husky-precommit-prepush-gith... More on stackoverflow.com
🌐 stackoverflow.com
Add documentation for `pre-push` hooks
The current Husky documentation mentions that hooks can run on push, but there is no explicit mention of pre-push hooks or how to implement them. This makes it unintuitive for new users who are only introduced to pre-commit in the documentation. ... The documentation should provide an example of ... More on github.com
🌐 github.com
2
February 11, 2025
bash - Husky: git commit --amend and push inside a pre-push hook - Stack Overflow
In order to make a continuous improvement script, inside my pre-push hook, I am trying to add a jest.config.js when it is changed, git commit --amend it, and push it: More on stackoverflow.com
🌐 stackoverflow.com
git - husky pre push hook before build - Stack Overflow
I'd like to implement a husky rule so as to make it run yarn build and make sure that what's going to be pushed won't break the app. I've browsed the web, but still not sure if the following is the More on stackoverflow.com
🌐 stackoverflow.com
🌐
Tighten
tighten.com › insights › husky-how-to-automatically-format-lint-and-test-before-you-commit-or-push
Husky: How to automatically format, lint and test before you commit or push | Tighten
March 14, 2024 - For example, imagine we have an undefined method in a JavaScript file. Husky will execute the first command, npm run format, without issues. It will then proceed to the second command, npm run lint, where it will encounter the error: ...
🌐
Medium
medium.com › @sawantkshitij070 › automating-code-quality-with-husky-how-to-use-pre-push-hooks-to-improve-your-git-workflow-d53d3ac2339c
Automating Code Quality with Husky: How to Use Pre-Push Hooks to Improve Your Git Workflow | by Kshitij Sawant | Medium
January 13, 2025 - In this guide, we’ll walk through the steps to integrate Husky with a React project and configure pre-commit and pre-push hooks to run tasks like linting, formatting, and testing.
🌐
Typicode
typicode.github.io › husky
Husky
Husky enhances your commits and more 🐶 woof! Automatically lint your commit messages, code, and run tests upon committing or pushing.
🌐
Faun
faun.pub › why-using-pre-push-git-hooks-with-husky-is-not-always-a-good-idea-6233b8afcf83
Why using pre-push Git Hooks with Husky is not always a good idea - FAUN.dev() 🐾
November 13, 2020 - Why using pre-push Git Hooks with Husky is not always a good idea In this short article, I would like to pay your attention to one of the hooks of npm package called Husky, but first things …
🌐
GitHub
github.com › typicode › husky
GitHub - typicode/husky: Git hooks made easy 🐶 woof!
Husky improves your commits and more 🐶 woof! ... Using React? See MistCSS typed CSS components. ... Check out the v9 changelog to discover all the new and improved features! ... Important Upgrading from v4 to v9 requires migrating previous config, please see the docs.
Starred by 35K users
Forked by 1.1K users
Languages   JavaScript 92.1% | Shell 7.9%
Find elsewhere
Top answer
1 of 2
6

Try changing your pre-push hook to: "npm run lint && git branch | grep \"*\" | egrep -v \"^* master$\""

This will cause git push to fail when the current branch is master

2 of 2
4

What I did was making a pre-push bash script and commit it inside the repository. Then call this script from husky pre-push hook with husky parameter.

This is my husky configuration inside package.json (you can set separated config if you want)

"husky": {
    "hooks": {
        "pre-commit": "./commands/pre-commit",
        "pre-push": "./commands/pre-push $HUSKY_GIT_STDIN"
    }
},

as you can see I have 2 scripts, one for pre-push and one for pre-commit.

And this is my commands/pre-push script

#!/bin/bash

echo -e "===\n>> Talenavi Pre-push Hook: Checking branch name / Mengecek nama branch..."

BRANCH=`git rev-parse --abbrev-ref HEAD`
PROTECTED_BRANCHES="^(master|develop)"

if [[ $1 != *"$BRANCH"* ]]
then
  echo -e "\n You must use (git push origin $BRANCH) / Anda harus menggunakan (git push origin $BRANCH).\n" && exit 1
fi

if [[ "$BRANCH" =~ $PROTECTED_BRANCHES ]]
then
  echo -e "\n Cannot push to remote $BRANCH branch, please create your own branch and use PR."
  echo -e " Tidak bisa push ke remote branch $BRANCH, silahkan buat branch kamu sendiri dan gunakan pull request.\n" && exit 1
fi

echo -e ">> Finish checking branch name / Selesai mengecek nama branch.\n==="

exit 0

The script basically will do 2 things:

  • This script will block anybody who tries to push to a certain branch (in my case I don't want anybody -including myself- to push directly to master and develop branch). They need to work in their own branch and then create a pull request.
  • This script will block anybody who tries to push to a branch that is different from their current active branch. For example you are in branch fix/someissue but then you mistakenly type git push origin master.

For more detailed instructions you can follow from this article:
https://github.com/talenavi/husky-precommit-prepush-githooks

🌐
GitHub
github.com › talenavi › husky-precommit-prepush-githooks
GitHub - talenavi/husky-precommit-prepush-githooks: Enable local pre-commit and pre-push git hooks using husky and prevent a push / commit to master or develop branch · GitHub
You don't want to distribute your pre-commit and pre-push script manually to everybody in your repository. You want to apply local-check before somebody push or commit to a certain branch. These bash scripts are basically similar to the one that is located inside .git/hooks/. However we will tweak it and put it inside our repository and the scripts will be called by husky https://github.com/typicode/husky (Husky can prevent bad git commit, git push and more 🐶 woof!) so it will be distributed to all members in your repository.
Starred by 20 users
Forked by 6 users
Languages   Shell
🌐
DEV Community
dev.to › aimes › pre-deployment-checklist-setting-up-husky-4i2k
Pre-deployment Checklist: Setting up Husky 🐶 - DEV Community
August 12, 2024 - touch .husky/pre-commit && touch .husky/pre-push # creates 2 new files inside the .husky directory · Inside the pre-commit hook file, we are going to run our test · and in the pre-push, we want to run our application build · Note: This is ...
🌐
GitHub
github.com › typicode › husky › issues › 1558
Add documentation for `pre-push` hooks · Issue #1558 · typicode/husky
February 11, 2025 - The current Husky documentation mentions that hooks can run on push, but there is no explicit mention of pre-push hooks or how to implement them. This makes it unintuitive for new users who are only introduced to pre-commit in the documentation. ... The documentation should provide an example of how to set up a pre-push hook, similar to how pre-commit is documented.
Author   ruslanpashkov
🌐
Medium
medium.com › @aryanm1729 › stop-broken-code-in-its-tracks-the-ultimate-guide-to-husky-and-pre-push-hooks-for-javascript-a057f680858b
Stop Broken Code in Its Tracks: The Ultimate Guide to Husky and Pre-Push Hooks for JavaScript Developers | by Aryan Mishra | Medium
June 18, 2025 - Pro Tip: Automate Husky setup for all contributors by adding a `prepare` script to package.json ... Now, every time someone runs `npm install`, Husky auto-initializes. ... #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" # Run full test suite npm run test # Lint the entire project npm run lint # Type-check (TypeScript projects) npm run type-check # Audit dependencies for vulnerabilities npm audit · How It Work 1. If any command fails (e.g., tests fail, linting errors exist), the push is aborted.
🌐
Khalil Stemmler
khalilstemmler.com › blogs › tooling › enforcing-husky-precommit-hooks
Enforcing Coding Conventions with Husky Pre-commit Hooks | Khalil Stemmler
March 10, 2020 - Husky is an npm package that "makes Git hooks easy". When you initialize Git (the version control tool that you're probably familar with) on a project, it automatically comes with a feature called hooks. If you go to the root of a project intialized with Git and type: ... You'll see a list of sample hooks like pre-push...
🌐
Leonardo Montini
leonardomontini.dev › home › blog › git hooks with husky 🐶
Git Hooks with Husky 🐶 | Leonardo Montini
July 10, 2023 - Husky already generated it for ... as an example. In our case we want to replace it with lint-staged. You can do it via the CLI but it’s also as easy as opening the file in .husky/pre-commit and replacing the last line with npx lint-staged. Make sure to run again npm install or yarn to install the hook and you’re done! This one is not generated by Husky, so we have to create it manually. You can either manually create a file called .husky/pre-push or run this ...
🌐
Syntackle
syntackle.com › blog › creating-git-hooks-using-husky-y6LKpN
Creating Git Hooks Using Husky
February 8, 2025 - Another example could be, if you want to minify javascript before pushing to production, you can use pre-push git hook. ... Find the list of various git hooks on the official git site.
🌐
iO Flood
ioflood.com › blog › husky-npm
Husky NPM Package Guide | Mastering Git Hooks Easily
April 18, 2024 - Here’s an example of how you can use Husky to run a test suite before a push, ensuring that your CI pipeline receives only the best code: npx husky add .husky/pre-push 'npm test' # Output: # husky > pre-push (node vxx.x.x) # [test suite output]
🌐
freeCodeCamp
freecodecamp.org › news › how-to-add-commit-hooks-to-git-with-husky-to-automate-code-tasks
How to Add Commit Hooks to Git with Husky to Automate Code Tasks
October 14, 2020 - “husky”: { “hooks”: { “applypatch-msg”: “echo \”[Husky] applypatch-msg\””, “pre-applypatch”: “echo \”[Husky] pre-applypatch\””, “post-applypatch”: “echo \”[Husky] post-applypatch\””, “pre-commit”: “echo \”[Husky] pre-commit\””, What this will do is tell Husky that at every single stage where we’re permitted to hook into Git, tell us! When I commit that change, we can immediately see that Husky fires off some of our scripts. These are all of the events that Git allows us to hook into that happen during the commit process. And similarly, if I push those changes out to Github, I can see that the push process runs the pre-push hook!
🌐
Medium
thevinaysingh.medium.com › ways-to-use-pre-commit-pre-push-hooks-in-react-react-native-22b851bc9331
Ways to use pre-commit, pre-push, and commit-msg hooks in React/React Native | by Vinay Singh | Medium
December 1, 2023 - Ways to use pre-commit, pre-push, and commit-msg hooks in React/React Native Agenda What are Git hooks? How to use pre-commit and pre-push? 1. Using husky and lint-staged 2. Using lefthook 3. Githubs …