gitreact-nativeatlassian-sourcetreegit-husky

Git push failed due to husky pre-push on sourcetree


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?


Solution

  • The issue (even though it's not a real issue! ) is because of the hooks created by Husky. 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. The quick solution, if you are too busy, 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. ) But it's always better to understand how Husky and hooks work and properly follow the lint warnings.

    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)