O'Reilly logo

Professional Git by Brent Laster

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15Extending Git Functionality with Git Hooks

Now that I’ve covered the overall Git workflow and functionality in detail, let’s look at one way you can extend and customize how Git works: hooks. Hooks are scripts or programs that run before or after (and in some cases during) a subset of operations in Git. There are hooks for local operations, such as commits or merges, and hooks for remote operations, such as when changes are pushed to the remote.

In some other source management systems, hooks may be called by other names, such as triggers. However, the concept is the same—a program or script runs when a certain event or operation happens. Here are some common uses for hooks:

  • Sending e-mail or other notifications when a change is pushed to a repository
  • Validating that certain conditions have been met before a commit
  • Appending items to commit messages
  • Checking the format or existence of certain elements in a commit message
  • Updating content in the working directory after an operation
  • Enforcing coding standards

INSTALLING HOOKS

By default, hooks exist in the hooks directory underneath your Git directory. Your Git directory is directly under your working directory unless you’ve overridden that location by setting a different value in the $GIT_DIR environment variable, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required