Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: checkout without running post-checkout hook

Tags:

git

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.

like image 367
dlu Avatar asked Feb 17 '16 03:02

dlu


3 Answers

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
like image 99
ruediste Avatar answered Sep 21 '22 14:09

ruediste


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 -- .
$ 
like image 26
Anthony Sottile Avatar answered Sep 17 '22 14:09

Anthony Sottile


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 :).

like image 36
larsks Avatar answered Sep 20 '22 14:09

larsks