Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an option to bypass or opt out of the hooks? #206

Closed
robdodson opened this issue Nov 20, 2017 · 9 comments
Closed

Is there an option to bypass or opt out of the hooks? #206

robdodson opened this issue Nov 20, 2017 · 9 comments

Comments

@robdodson
Copy link

Sometimes when I'm working on a project I might be experimenting in a branch and knowingly doing stuff that's wrong or might make my linter mad. Is there a way to tell husky to ignore my commit and not run a hook against it? I guess I could write this myself with an environment variable but it seems like a possibly useful husky option.

@AlaaAttya
Copy link

yes you can just write git commit -m "bla bla" -n
the -n will get you bypass the hooks

@AlaaAttya
Copy link

also you can use git commit --no-verify and git push --no-verify
-n means no verify

@robdodson
Copy link
Author

oh thanks! I just learned about the --no-verify flag 😄

@timotgl
Copy link

timotgl commented Mar 9, 2018

Another, although radical option is to move the files in .git/hooks out of this directory, if you never want to run them for the current repo and can't be bothered to add --no-verify to every git command. The hooks come back if husky is reinstalled though.

@pascalgn
Copy link

pascalgn commented Mar 9, 2019

For anyone who arrives here from Google: You can also use the core.hooksPath git configuration option, so for example

git -c core.hooksPath=/dev/null checkout master
git -c core.hooksPath=/dev/null pull
git -c core.hooksPath=/dev/null commit ...
git -c core.hooksPath=/dev/null push
...

@DesignByOnyx
Copy link

I'm spreading this information around as it's super useful:

As of v2.4.0 you can now do HUSKY_SKIP_HOOKS=1 git <command> ...

@yrammos
Copy link

yrammos commented Oct 1, 2019

@DesignByOnyx this does not seem to skip the post-commit hook, unfortunately.

@DesignByOnyx
Copy link

@yrammos - if what you say is true, you should report a bug. However, looking at the code, it appears that husky exits early if you use HUSKY_SKIP_HOOKS=1 or HUSKY_SKIP_HOOKS=true. Can you try running your script with HUSKY_DEBUG=1?

if [ "$\{HUSKY_SKIP_HOOKS}" = "true" ] || [ "$\{HUSKY_SKIP_HOOKS}" = "1" ]; then

Also, if you are calling git commands from a child process (eg. through npm scripts in package.json), then you might need to forward any environment variables manually:

HUSKY_SKIP_HOOKS=1 npm run commit-my-code

... and in your package.json:

{
  "scripts": {
    "commit-my-code": "HUSKY_SKIP_HOOKS=$HUSKY_SKIP_HOOKS git commit"
  }
}

@ghedsouza
Copy link

ghedsouza commented Jun 17, 2021

For commands like push, current solution is to set HUSKY=0 as an environment variable in your command, like so:

HUSKY=0 git push # yolo!

(Documented at https://typicode.github.io/husky/#/?id=bypass-hooks).

HUSKY_SKIP_HOOKS no longer works (as of at least 6.0.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants