Git husky is a Git hook. Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Use this tag for questions specifically about Git husky, not for questions about Git hooks in general.
Questions tagged [git-husky]
92 questions
6
votes
0 answers
Pending git changes are lost when commit fails due to linting error (husky + lint-staged)
I have an Angular app using git and Visual Studio Code. I set up ESLint and am using husky to run lint-staged in a pre-commit hook, so that changes with linting errors cannot be committed.
When I first set it up, the pending changes in failed…

Roobot
- 860
- 1
- 10
- 20
6
votes
1 answer
Unstaged changes could not be restored due to a merge conflict
When I execute git commit -m "commit message" command, lint-staged shows this error:
My configuration in package.json:
"husky": {
"hooks": {
"pre-commit": "npm run validate && lint-staged"
}
},
"lint-staged": {
"*.+(js|ts|tsx)":…

Arif
- 6,094
- 4
- 49
- 81
5
votes
1 answer
Run Husky hooks only for specific folder changes
Is it possible to run only git hooks for when only files in certain folder are changed??
I have monorepo with backend and frontend. I would like to run husky hook only when the files in frontend got changed. Otherwise it should not be triggered and…

Mugetsu
- 1,739
- 2
- 20
- 41
5
votes
1 answer
Run tests with husky pre-push only when there are changes
As in the title, at the moment I have configured my app to run tests every time a git push is executed,
"husky": {
"hooks": {
"pre-push": "npm run test:unit"
}
}
but evidently it does not scale well, the more tests the more time it…

Andrea
- 351
- 1
- 3
- 9
4
votes
1 answer
Can't commit using husky: .husky/pre-commit: line 4: npx: command not found
I have installed husky and it was working fine for months and then out of the blue today after a restart this error came up:
husky - command not found in…

mishchief
- 412
- 3
- 13
4
votes
1 answer
Husky Hook does not work properly with Test
I'm configuring Husky to block commits if the prettier or eslint accuses both an error or warn, and block the push if it doesn't pass the tests.
However, when running the test, the test CLI is displayed (it is in the image below), with this, no key…

THIAGO DE BONIS
- 760
- 7
- 22
4
votes
1 answer
How to run husky pre-push hook only when pushing to a certain branch of a certain remote?
Say I am working with multiple remotes:
$ git remote -v
origin https://github.com/ettie62/Quicke(fetch)
origin https://github.com/ettie62/Quicke(push)
public https://github.com/roslyn80/Quicke(fetch)
public …

Kazuto_Ute
- 679
- 6
- 20
4
votes
2 answers
Setup pre-push hook with Husky to prevent pushing to master branch
Is it possible to setup pre-push hook with Husky to prevent pushing to master by mistake??
Husky documentation is very poor so I couldn't find the answer.
Right now I have husky set for committing and pushing like this:
"husky": {
"hooks": {
…

p7adams
- 622
- 1
- 9
- 24
4
votes
0 answers
Unable to setup input stream: unable to set IO streams as raw terminal: The handle is invalid
I am trying to use 'husky' to implement git hooks. I installed husky as a dev-dependancy and included a command in the scripts object. When I try to run the command 'git commit' I receive the following error:
$git commit -m "first commit"
unable to…

Sai Raman Kilambi
- 878
- 2
- 12
- 29
3
votes
0 answers
husky install - .git can't be found - issue in local mac machine
I am facing this issue only for 1 project other similar react-native-based applications not facing any issue. I have also tried removing the husky references from my project, still getting the same error.

Sandeep Rajbhar
- 93
- 1
- 10
3
votes
2 answers
Unable to commit due to Husky failure in node application
I have created a node application and installed Husky7.0.4 and lint-staged12.3.5
following are the configuration for
.husky/pre-commit --- file
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run pre-commit
and following are the package.json…

Avinash A
- 665
- 1
- 7
- 22
3
votes
1 answer
Husky hook post-merge checking if any changes on package.json and execute npm install if detected changes
I want to the hook to do something like run NPM install after merge branch but only if package.json file is being modified
I'm not sure if I'm doing it correctly, please find my post-merge below
#!/bin/sh
. "$(dirname…

user7755725
- 55
- 5
3
votes
0 answers
Using lint-staged to check this commit is going to build ok?
When using husky and lint-staged is it possible to check what is staged builds in the pre-commit?
Kind of like this?
"lint-staged": {
"**/*.{js,jsx,ts,tsx,css,md}": [
"prettier --write",
"yarn build"
]
}
If I try this I get a…

user1259167
- 447
- 5
- 15
3
votes
0 answers
ESLint configuration with react-scripts not working
I want to configure eslint as a precommit hook and my project is made using create-react-app. I have the following configuration with me currently. But with the following Lint staged is not running before commits. Also, I cannot install any other…

Aayushi
- 1,736
- 1
- 26
- 48
3
votes
1 answer
error Parsing error: Unexpected character '#' in md file
Everything was fine, until I added lint-staged using husky.
I got error related to README.md
packages\README.md
1:1 error Parsing error: Unexpected character '#'
> 1 | # @folo/forms
| ^
In package.json:
"husky": {
"hooks": {
…

Jalal
- 3,308
- 4
- 35
- 43