How to skip Git commit hooks

avatar

Borislav Hadzhiev

Last updated: Apr 11, 2022

banner

Photo from Unsplash

Skip Git commit hooks #

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.

shell
git commit -m "commit message" --no-verify git push --no-verify

You can also use the -n option, which is short for --no-verify.

shell
git commit -m "commit message" -n

git commit skip hooks

If you use the husky package for your git hooks, you can also prefix the command with the HUSKY=0 environment variable.

shell
# HUSKY=0 git YOUR_COMMAND_HERE HUSKY=0 git commit -m "commit message" HUSKY=0 git cherry-pick --continue

husky skip commit hooks

If the suggestions above didn't solve your issue, you can comment out the specific git hook by:

  1. Opening the file where the git hook is stored, e.g. .git/hooks/pre-commit.
  2. Commenting out the line that runs the hook, e.g. # . "$(dirname "$0")/husky.sh".
  3. Running your git command.

The hooks are located in the .git/hooks/ directory.

The --no-verify option can be used to bypass the pre-commit and commit-msg hooks.

The pre-commit hook is run first and is used to inspect the snapshot that's about to be committed.

The pre-commit hook can be used to run tests, lint, type check, etc. If the hook exists with a non-zero code, the commit is aborted.

The commit-msg hook is also skipped by the --no-verify option. This hook is invoked when using the git commit or git merge commands.

The hook is used to make sure that our commit message conforms to a required pattern.

If the commit-msg hook exists with a non-zero code, the commit is aborted.

After the pre-commit and commit-msg hooks run, the post-commit hook runs. This hook is often used for notification purposes.

The pre-merge-commit hook can also be bypassed with the --no-verify option. This hook is invoked after the merge has been carried out successfully and before obtaining the commit log message.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.