Git push failed due to husky pre-push on sourcetree
Solution 1
The issue (even though it's not a real issue! ) is because of the hooks created by React. The solution is to simply delete the hooks folder for git which defines the pre-commit hooks and hence can push after that. (This is just kind of a hack to avoid editing thousands of files at a time for lint errors. Follow the guidelines and resolve all the lint errors for better code quality and maintainability. )
Edit: You can also skip hooks when you provide the git command line argument —no-verify,
git push origin master --no-verify
, or use Sourcetree‘s Bypass commit hooks setting (in the menu to the top right of the commit message field)
Solution 2
I thought it equally important to help you understand the husky
tool.
And I found this article very helpful in managing this situation, when I struggled too.
Husky is an npm package that lets you define npm scripts that correlate to local Git events such as a commit or push. And this helps in enforcing collaborative standards in a project.
In your project, you mention that all errors are linked to linting.
So in there, husky
scripts were written to create a git hook
, called pre-push
, which enforces code linting before you can git push
successfully.
In my opinion, especially if you are working in a team, DO NOT turn-off/deactivate these checks and DO NOT delete the .git/hooks
folder. Instead go back and run the lint script
(often found in the package.json
), amend the required changes and once you git push
again you'll be successful.
Solution 3
Add --no-verify
flag to the end of your push command.
git push origin master --no-verify
Comments
-
krishnakumarcn almost 2 years
While pushing a react native project, I'm getting error due to husky pre-push failed
husky > pre-push hook failed (add --no-verify to bypass)
All these errors shown are lint errors like the below
unused-vars 27:48 error Trailing spaces not allowed no-trailing-spaces 75:5 warning Unexpected console statement no-console 92:93 error Unexpected trailing comma comma-dangle 96:81 error Unexpected trailing comma
How to turn this off on Sourcetree app on mac?
-
12Bo about 5 yearsI tried everything... updating husky@letest, removing node_modules, npm i, npm rebuild but simply removing the hooks folder worked. Unfortunately, next time I run npm i it will break.
-
krishnakumarcn about 5 yearsnpm install will again install those hooks. so better to delete it every time or spend some time to follow the lint rules so that your project will be on a good style. @12Bo
-
fabb about 5 yearsYou can also skip hooks when you provide the git command line argument
—no-verify
, or use Sourcetree‘s „Bypass commit hooks“ setting (in the menu to the top right of the commit message field) -
Lucky Lam over 4 yearsThe "Bypass commit hooks" isn't working for me. I'm using Sourcetree on Windows
-
MwamiTovi about 4 years
husky
is an npm package that helps enforce coding standards especially in large projects before yougit push/commit
. And thehusky
scripts are many times written in thepackage.json
file or.huskyrc
config file. But for your case, chances are you hadhusky
uninstalled but thegit hooks
were still in there. -
Julio Feferman about 3 yearsYou are essentially overriding the pre-push hook by using the
--no-verify
flag. The errors from husky are self explanatory. Fix those and the push should work.