I have a post-checkout hook that I like – most of the time – but from time to time I know that it would be waste of time to run it, or, since it drops and rebuilds my development database, I don't want it to do its thing.
Is there a git option that skips hooks? So fair I've struck out looking for one.
I just found another answer. Just add the -c core.hooksPath=/dev/null
option to your git command. This overrides the configuration just for one command, and disables all hooks. For ecample:
git -c core.hooksPath=/dev/null checkout master
git -c core.hooksPath=/dev/null pull
git -c core.hooksPath=/dev/null commit ...
git -c core.hooksPath=/dev/null push
You can do this from the command line by forcing core.hooksPath
to be a path which does not exist (via -c
)
for example:
$ cat .git/hooks/post-checkout
#!/usr/bin/env bash
echo 'nope'
exit 1
$ git checkout -- .
nope
$ git -c core.hooksPath=/dev/null checkout -- .
$
I don't think there's a command line option to do what you want, but you can trivially solve this by using an environment variable as a flag. In your post-checkout
script, start with:
#!/bin/sh
[ "$SKIP_POST_CHECKOUT" = 1 ] && exit 0
And then when you want to skip the post-checkout
script:
SKIP_POST_CHECKOUT=1 git pull
Etc.
And you can always make your variable name shorted if that's too much to type :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With