Git: checkout without running post-checkout hook

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

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


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 -- .
$ 

Tags:

Git