10

Given that I need to use git inside my hook scripts, I would prefer my hook scripts to not trigger hooks themselves. So I want to skip hooks on a per-command basis.

i.e. I am looking for an option like:

git --no-hooks some-git-command

1
  • 3
    For commit hooks, you've got the --no-verify option.
    – Philippe
    Commented Oct 11, 2019 at 11:06

3 Answers 3

11

You can use:

git -c core.hooksPath=/dev/null some-git-command

If you are not on an Unix (no /dev/null) I suppose that you can use:

git -c core.hooksPath= some-git-command

3
  • Would you suggest a solution for disabling only one hook (e.g: .git/hooks/post-commit) selectively (still issuing from the command line)?
    – bloody
    Commented Dec 10, 2020 at 13:42
  • Maybe create a directory .git/all-hooks-but-one that contains symlinks to all hooks but the one you want to disable, add use git -c core.hooksPath=.git/all-hooks-but-one ? Not ideal though: some OSes do not support symlinks and you need to update the links when adding/removing/renaming new hooks. Commented Dec 10, 2020 at 14:13
  • For a record - I've found attractive solution: hook controlled from command line. Simple as a hell:) Anyway +1 for yours for the general way as well.
    – bloody
    Commented Dec 10, 2020 at 14:52
4

Another rougher idea.

  1. Just comment lines in file .git/hooks/pre-commit with symbol '#'.
  2. Run single or many commands
  3. Uncomment
  4. Profit.
1

If you are on unix, and want to disable one or more hook, you can simply do a :

chmod -x .git/hooks/MYHOOK ; git COMMAND ; chmod +x .git/hooks/MYHOOK; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.