1.3 KiB
Skip Git Hooks As Needed
Projects have Git hooks configured for all sorts of reasons. Most common are
pre-commit hooks which verify certain aspects of the contents of a commit.
A pre-commit hook could check that the tests all pass, that the changes don't
include any debugging statements, and so forth. There are all kinds of hooks
though, like pre-rebase and post-checkout.
These hooks can sometimes get in the way and we may need to skip or disable them on a one-off basis.
Several Git commands offer a --no-verify flag which can skip running the hook
associated with that command.
git commit --no-verify(skipspre-commitandcommit-msghooks)git push --no-verify(skipspre-pushhook)git merge --no-verify(skipspre-merge-commithook)git am --no-verify(skipsapplypatch-msgandpre-applypatchhooks)
If you look in the .git/hooks directory, there are several other hooks not
covered by the above. So, what if I am doing an action like git checkout and I
want to skip the post-checkout hook?
I can override the hooksPath config for that one command with the -c flag.
$ git -c core.hooksPath=/dev/null checkout ...
By setting it to /dev/null, it will find no hooks available, so none will be
executed for this command.
See man git-config for more details on core.hooksPath.