1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-11 02:58:01 +00:00

Add Skip Git Hooks As Needed as a Git TIL

This commit is contained in:
jbranchaud
2026-01-09 21:23:55 -06:00
parent e95477607e
commit 712fc66aae
2 changed files with 35 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1722 TILs and counting..._
_1723 TILs and counting..._
See some of the other learning resources I work on:
@@ -426,6 +426,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Show What Is In A Stash](git/show-what-is-in-a-stash.md)
- [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md)
- [Skip A Bad Commit When Bisecting](git/skip-a-bad-commit-when-bisecting.md)
- [Skip Git Hooks As Needed](git/skip-git-hooks-as-needed.md)
- [Skip Pre-Commit Hooks](git/skip-pre-commit-hooks.md)
- [Staging Changes Within Vim](git/staging-changes-within-vim.md)
- [Staging Stashes Interactively](git/staging-stashes-interactively.md)

View File

@@ -0,0 +1,33 @@
# Skip Git Hooks As Needed
Projects have Git hooks configured for all sorts of reasons. Most common are
`pre-commit` hooks which verify certain aspects of the contents of a commit.
A `pre-commit` hook could check that the tests all pass, that the changes don't
include any debugging statements, and so forth. There are all kinds of hooks
though, like `pre-rebase` and `post-checkout`.
These hooks can sometimes get in the way and we may need to skip or disable them
on a one-off basis.
Several Git commands offer a `--no-verify` flag which can skip running the hook
associated with that command.
- `git commit --no-verify` (skips `pre-commit` and `commit-msg` hooks)
- `git push --no-verify` (skips `pre-push` hook)
- `git merge --no-verify` (skips `pre-merge-commit` hook)
- `git am --no-verify` (skips `applypatch-msg` and `pre-applypatch` hooks)
If you look in the `.git/hooks` directory, there are several other hooks not
covered by the above. So, what if I am doing an action like `git checkout` and I
want to skip the `post-checkout` hook?
I can override the `hooksPath` config for that one command with the `-c` flag.
```sh
$ git -c core.hooksPath=/dev/null checkout ...
```
By setting it to `/dev/null`, it will find *no* hooks available, so none will be
executed for this command.
See `man git-config` for more details on `core.hooksPath`.