Git push failed due to husky pre-push on sourcetree

35,207

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
Share:
35,207
krishnakumarcn
Author by

krishnakumarcn

Engineer. Flutter Evangelist

Updated on July 09, 2022

Comments

  • krishnakumarcn
    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
    12Bo about 5 years
    I 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
    krishnakumarcn about 5 years
    npm 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
    fabb about 5 years
    You 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
    Lucky Lam over 4 years
    The "Bypass commit hooks" isn't working for me. I'm using Sourcetree on Windows
  • MwamiTovi
    MwamiTovi about 4 years
    husky is an npm package that helps enforce coding standards especially in large projects before you git push/commit. And the husky scripts are many times written in the package.json file or .huskyrc config file. But for your case, chances are you had husky uninstalled but the git hooks were still in there.
  • Julio Feferman
    Julio Feferman about 3 years
    You 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.