Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 307
krishnakumarcn Avatar asked Oct 11 '18 06:10

krishnakumarcn


People also ask

How do you ignore a husky pre-commit?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.

How do I disable my husky?

You can set HUSKY environment variable to 0 in your CI config file, to disable hooks installation. Alternatively, most Continuous Integration Servers set a CI environment variable. You can use it in your hooks to detect if it's running in a CI.

What is husky pre-commit?

Husky is a very popular (1 million downloads a month) npm package that allows custom scripts to be ran against your repository. Husky works with any project that uses a package. json file. It also works out of the box with SourceTree!

How do I ignore pre-commit?

Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!

How to fix bad git commit error in Husky?

Husky can prevent you from bad git commit, git push and more. If you are getting this error check your code syntax, in case if you are getting this error even your code is valid. Please use the below command. Delete the .git/hook folder and then uninstall and reinstall husky.

Why can't I push from react to Git?

The issue (even though it's not an issue! ) is because of the hooks created by react. I simply deleted 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.

What is pre-push in Husky scripts?

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.

Why is my husky > pre-commit hook failing?

In my case I started getting husky > pre-commit hook failed (add --no-verify to bypass) once some dependencies have been updated. The problem was solved by changing Husky's pre-commit linting command to npm run lint (usually this one works fine in most cases) in husky file:


2 Answers

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)

like image 108
krishnakumarcn Avatar answered Oct 14 '22 00:10

krishnakumarcn


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.

like image 39
MwamiTovi Avatar answered Oct 13 '22 23:10

MwamiTovi