Skip to Content
Version Control with Git, 2nd Edition
book

Version Control with Git, 2nd Edition

by Jon Loeliger, Matthew McCullough
August 2012
Intermediate to advanced
452 pages
12h 39m
English
O'Reilly Media, Inc.
Content preview from Version Control with Git, 2nd Edition

Chapter 15. Hooks

You can use a Git hook to run one or more arbitrary scripts whenever a particular event, such as a commit or a patch, occurs in your repository. Typically, an event is broken into several prescribed steps, and you can tie a custom script to each step. When the Git event occurs, the appropriate script is called at the outset of each step.

Hooks belong to and affect a specific repository and are not copied during a clone operation. In other words, hooks you set up in your private repository are not propagated to and do not alter the behavior of the new clone. If for some reason your development process mandates hooks in each coder’s personal development repository, arrange to copy the directory .git/hooks through some other (nonclone) method.

A hook runs either in the context of your current, local repository or in the context of the remote repository. For example, fetching data into your repository from a remote repository and making a local commit can cause local hooks to run; pushing changes to a remote repository may cause hooks in the remote repository to run.

Most Git hooks fall into one of two categories:

  • A pre hook runs before an action completes. You can use this kind of hook to approve, reject, or adjust a change before it’s applied.

  • A post hook runs after an action completes and can be used to trigger notifications (such as email) or to launch additional processing, such as running a build or closing a bug.

As a general rule, if a pre-action hook exits ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Version Control with Git

Version Control with Git

Jon Loeliger
Version Control with Git, 3rd Edition

Version Control with Git, 3rd Edition

Prem Kumar Ponuthorai, Jon Loeliger
Git for Programmers

Git for Programmers

Jesse Liberty

Publisher Resources

ISBN: 9781449345037Errata Page