Git push failed due to husky pre-push on sourcetree
Asked Answered
C

4

22

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?

Catalano answered 11/10, 2018 at 6:57 Comment(2)
Going in the other direction, if you think these rules are good, then you could configure your IDE to automatically format your source file to strip off trailing spaces, etc. This might be what I would be looking to do here.Scarletscarlett
@TimBiegeleisen I understand that. But there are like hundreds of suggestions/errors there and I want to push it ASAP. These lint errors are not shown in my team members system while he is trying to push. Using the same Sourcetree version.Catalano
C
35

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)

Catalano answered 11/12, 2018 at 8:23 Comment(5)
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.Communitarian
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. @CommunitarianCatalano
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)Unexpected
The "Bypass commit hooks" isn't working for me. I'm using Sourcetree on WindowsDilapidate
This answer seems to conflate the 'hooks' associated with Husky and the 'hooks' associated with React. And those hooks are not the same. I would recommend just deleting the line "The issue (even though it's not a real issue! ) is because of the hooks created by React."Purdah
K
12

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.

Kauppi answered 9/2, 2020 at 5:2 Comment(1)
This is the right solution to the problem: "run the lint script... amend the required changes and... git push again".Ferneferneau
M
5

Add --no-verify flag to the end of your push command.

git push origin master --no-verify
Myrica answered 1/3, 2020 at 6:14 Comment(1)
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.Avert
A
-1

Add --no-verify to the end of your commit short term.

I'm also on Mac and started seeing these I think with working on a Carlo app that I instantiated inside my main project folder. I came Googling over to stack overflow due to I wasn't sure what Husky is ('husky' command not installed), so I started digging around to find a linter, guessed to try eslint .

➜  src_aminosee git:(master) ✗ eslint .
Error: Cannot find module '@ljharb/eslint-config'
Referenced from: /Users/tom/Dropbox/Sites/funk.co.nz/aminosee/carlojet/node_modules/array-includes/.eslintrc

This is when I realised that I have a git repo inside of a git repo here ('carlojet' try out folder inside 'aminosee' main project)!! I'd have to (should) move that folder out. Not sure if this type of nested repo issue is what was causing your issue, but after moving thusly and attempt a commit I see:

git commit -am "moved carlojet folder out as i think its git repo conflicted with this main one"
Can't find Husky, skipping pre-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping prepare-commit-msg hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping commit-msg hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping post-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook

My knowledge of git is lacking, but to me, it's like those files are now waving "good bye" having left the repo; or more likely "winking" at me having up traversed into their parents aminosee/.git/hooks/ directory (that was a surprise!), from their true home in aminosee/carlojet/.git/hooks/

I may need to disable all these hooks duplicated from other project... or better still bring up that linter! I guess not great idea to nest git repo inside itself in my case.

Abortionist answered 6/8, 2019 at 15:37 Comment(1)
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.Kauppi

© 2022 - 2024 — McMap. All rights reserved.