brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git commit -n skips the pre-commit hook when you really need to

Git
~/tips/tip-git-commit-no-verify-skip-hooks

git commit --no-verify -m "WIP: half done export"

Bypasses the pre-commit and commit-msg hooks for one commit.

A pre-commit hook that lints and tests is great, until you just want to save a work-in-progress commit before switching branches. Git has a way around it for one commit.

git commit --no-verify -m "WIP: half done export"

--no-verify, or -n for short, makes git skip the pre-commit and commit-msg hooks for this commit. Other hooks, like post-commit, still run. git push has the same option for the pre-push hook.

I’d use it for commits you’ll squash or rewrite later anyway. A WIP commit before a quick switch, or a commit on a branch you’re about to rebase. When the real version goes in, the hooks get their turn.

It’s also handy when a hook is broken, for example a linter that crashes after an update, and you need to commit the fix for that same hook.

Skipping hooks doesn’t skip the checks on the server. If your CI runs the same lint and tests, a commit made with -n still fails there, just later and in public. And don’t make it a habit or an alias. Once the hooks are skipped by default, they protect nothing, and the first time you notice is when broken code is already pushed.

Further reading: git-commit documentation, githooks documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link