Tom Hale
Tom Hale

Reputation: 46775

Skip some or all git hooks

I've got a post-checkout hook that takes some time to run, and I want to skip it if I'm bouncing around between branches doing fix-ups.

How can I generically skip the execution of some or all git hooks?

Upvotes: 3

Views: 1584

Answers (2)

yuwang
yuwang

Reputation: 876

An environment variable e.g. DISABLE_POST_CHECKOUT is probably what you want. Tweak your post-checkout hook with it. See also: https://stackoverflow.com/a/9730976/654952

Upvotes: 4

ElpieKay
ElpieKay

Reputation: 30868

Here is one of the possible solutions.

Define a config key, like my.hook as the switch to enable or disable the hooks. Further more, my.hook.post-checkout to enable or disable post-checkout only. But you will have to deal with the keys and values in every of your hooks if you want them to work.

git config --global my.hook true
git config my.hook.post-checkout false

A post-checkout demo,

#!/bin/bash

test x`git config --get my.hook` == x"false" && exit 0
test x`git config --get my.hook.post-checkout` == x"false" && exit 0
echo hello world

Upvotes: 2

Related Questions