sajad torkamani

What is a Git hook?

A Git hook is essentially some bit of code/script that you run when something happens in Git. A very common example of a hook is running a linter like Rubocop before each Git commit.

What is Overcommit?

Overcommit is a tool that makes managing your hooks less of a pain in the ass.


Add to your Gemfile and run bundle

group :development, :test do
  gem 'overcommit'

Install the hooks for your project and generate a .overcommit.yml config file:

overcommit --install
overcommit --sign # May need to run if you get an error

Add a hook

Let's setup a pre-commit hook to run Rubocop. Edit your .overcommit.yml file:

    enabled: true
    on_warn: fail # Treat all warnings as failures

Overcommit has a bunch of built-in hooks but you can also add custom hooks if needed.

List hooks in project

overcommit -l


Tagged: Ruby