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
🌐
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.
🌐
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 onl...
Author   ruslanpashkov
🌐
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 - Husky helps automate essential quality checks by adding custom Git hooks that run scripts before commits or pushes. Here’s why it’s beneficial for your workflow: Automated Code Quality: Husky can automatically run code formatters (like Prettier) ...
🌐
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%
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

🌐
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 - Husky is a npm package which is quite popular (now it has 1,2 mln weekly downloads) and can help with git hooks like commit or push. Installing Husky is very simple you only need to type: ... I was very excited about husky but my teammate have pay my attention to one fact related to a pre-push hook.
🌐
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 - Linters analyze the code to detect and fix issues, enforce best practices, and prevent common errors. (formatters vs. linters) Testing frameworks validate the application's functionality against expected outcomes. These tools are fantastic, but there's a catch: you and your teammates must remember to run them before pushing code to the repository. And, being humans, sometimes you might forget to do so. That's why today we'll talk about Husky, a tool that automatically runs any number of commands whenever you commit or push.
Find elsewhere
🌐
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
Enable local pre-commit and pre-push git hooks using husky and prevent a push / commit to master or develop branch - talenavi/husky-precommit-prepush-githooks
Starred by 20 users
Forked by 6 users
Languages   Shell
🌐
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 - Husky is a Git hook manager that allows you to set up pre-commit and pre-push hooks easily. To install Husky, open your terminal and navigate to your project directory.
🌐
Leonardo Montini
leonardomontini.dev › home › blog › git hooks with husky 🐶
Git Hooks with Husky 🐶 | Leonardo Montini
July 10, 2023 - And that’s it! With husky you can make sure everyone in your team has all the required git hooks always set! Today we showcased only pre-commit and pre-push, but husky supports all available git hooks.
🌐
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, pre-rebase, pre-commit, and so on.
🌐
Medium
medium.com › @diego.coder › asegurando-la-calidad-de-commits-con-git-hooks-en-node-js-y-husky-0dd6adaa3f26
Mejora la Calidad de tus Commits con Git Hooks y Husky en Node.js 🤩👌👨‍💻 | by Code & Chill | Medium
February 28, 2025 - Variedad de ganchos soportados: Husky es compatible con una variedad de ganchos de Git, como pre-commit, pre-push, post-merge, entre otros.
🌐
GitHub
github.com › typicode › husky › issues › 1303
a commit done in pre-push is not pushed · Issue #1303 · typicode/husky
September 21, 2023 - Probably not a real issue, perhaps something is missing in my hook… Here's my pre-push hook (to build a cjs version before pushing), with husky 8.0.3 #!/bin/sh . "$(dirname "$0")/_/husky.sh" if pnpm test && pnpm run build; then # commit ...
Author   dcaillibaud
🌐
GitHub
github.com › typicode › husky › issues › 646
Problem with the pre-push git hook · Issue #646 · typicode/husky
January 14, 2020 - After installing the husky latest version (4.0.9) and setting the following hooks in the package.json file, ... "husky": { "hooks": { "pre-push": "npm run test&qu...
Author   tzeikob
🌐
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 - Configure by creating a file or folder: - Create a lint-staged.js file at the root of your project - Run npx husky install at root, this will create a .husky folder at the root of your project. - To add a pre-push hook, create a .husky/pre-push file. - To add a pre-commit hook, create a .husky/pre-commit file.
🌐
DEV Community
dev.to › kreshby › keep-your-code-clean-with-eslint-prettier-pre-commit-and-pre-push-hooks-using-husky-lint-staged-and-pretty-quick-4fka
Keep your code clean with ESLint, prettier, pre-commit and pre-push hooks using husky, lint-staged, and pretty-quick - DEV Community
February 12, 2023 - Now, it's time to set up Husky and lint-staged. Pre-commit and pre-push hooks are used to run scripts before you commit changes to your Git repository or before you push changes to a remote repository.
🌐
Stack Overflow
stackoverflow.com › questions › 66345812 › how-to-run-husky-pre-push-hook-only-when-pushing-to-a-certain-branch-of-a-certai
git - How to run husky pre-push hook only when pushing to a certain branch of a certain remote? - Stack Overflow
git-husky · Share · Improve this question · Follow · asked Feb 24, 2021 at 6:35 · Kazuto_Ute · 8171010 silver badges2929 bronze badges · Add a comment | Sorted by: Reset to default · Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 0 · That hook might very well run for every branch, so you should call a script which would: get the parameters from the pre-push hook, as in husky issue 757 ·
🌐
DEV Community
dev.to › aimes › pre-deployment-checklist-setting-up-husky-4i2k
Pre-deployment Checklist: Setting up Husky 🐶 - DEV Community
August 12, 2024 - Inside this directory, we are going to create our two new hooks: pre-commit and pre-push. touch .husky/pre-commit && touch .husky/pre-push # creates 2 new files inside the .husky directory