Book Your Free Call

How To Skip Commit Hooks In Git (No-Verify)

Tim Mouskhelichvili
Tim Mouskhelichvili
2 minutes to read

Sometimes, developers need to quickly commit and skip the hooks set up on the Git repository. Luckily, developers can easily skip those hooks because the git commit command provides a handy option called no verify.

To skip the pre-commit and the commit-msg hook, use this command:

bashgit commit --no-verify -m "message"

This article will explore the pre-commit hook, the commit-msg hook, and how to skip them when committing.

Let's get to it 😎.

git commit no verify

First, let's look at the hooks that we can skip with the --no-verify option.

What is the pre-commit hook?

The pre-commit hook runs first after a commit and inspects the files changed by the commit.

This hook can run tests, linting, and other types of checks.

The commit is aborted if the pre-commit hook EXITS with anything other than ZERO.

Note: I like to use husky for managing git hooks.

What is the commit-msg hook?

The commit-msg hook runs after the pre-commit hook.

This hook checks that the commit message conforms to a set standard.

For example, we can ensure that all our commits start with a verb and end with a comma.

Note: Commitlint is an excellent npm package that I use for linting commit messages.

Why skip the pre-commit hook?

If the pre-commit validation fails, the commit is aborted, so you will not be able to push it to a remote.

There are a few reasons to skip the pre-commit hook:

  • For testing purposes.
  • When you need to push a fix quickly.

However, bypassing this hook isn't a good idea, and you should only do it if you are sure of what you are doing and after thoughtful consideration.

How to skip the commit hooks?

To skip the pre-commit and the commit-msg hooks, use this command:

bashgit commit --no-verify -m "message"

Or use an alias to the --no-verify option, like so:

bashgit commit -n -m "message"

Alternatively, you can comment out the pre-commit hook located in the .git/hooks/ folder and try to commit your changes again.

Final thoughts

As you can see, skipping the commit hooks is easy to achieve in Git. Just use the git commit command with the --no-verify option.

git pre-commit hook

Here are other Git tutorials that I wrote for you to enjoy:

Comments (0)