.git/hooks/pre-commitGit Hooks
Git hook locations, setup patterns, and reusable client-side hook snippets for linting, testing, policy, and automation.
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
Client-Side Hooks
Hooks executed during local developer workflows.
bash
bash
.git/hooks/commit-msgbash
.git/hooks/pre-pushbash
chmod +x .git/hooks/pre-commitbash
git config core.hooksPath .githooksHook Snippets
Practical scripts users often search for and adapt.
bash
#!/usr/bin/env sh
npm run lintbash
#!/usr/bin/env sh
npm testCommit-msg conventional commits validator
Reject non-conforming commit messages.
shANYhookscommit-msgconventional-commits
bash
#!/usr/bin/env sh
grep -Eq "^(feat|fix|docs|chore|refactor|test)(\(.+\))?: .+" "$1"bash
#!/usr/bin/env sh
branch="$(git symbolic-ref --short HEAD)"
[ "$branch" = "main" ] && echo "Direct pushes to main are blocked." && exit 1
exit 0bash
#!/usr/bin/env sh
npm installHook Lifecycle Commands
Commands and patterns used while developing or debugging hooks.
bash
git config --show-origin --get core.hooksPathSkip client hooks for one commit
Bypass pre-commit and commit-msg hooks when necessary.
bashANYhooksbypassdanger
bash
git commit --no-verify -m "Emergency commit"bash
git push --no-verifybash
set -x
# add near top of hook scriptMore in Git
Git Patch and Email Workflows
Patch-oriented Git workflows using format-patch, apply, am, and range-diff for mailing-list and review-based collaboration.
Git Internals and Plumbing
Low-level Git objects, refs, trees, index, commit creation, and packfile plumbing for advanced users and debugging.
Git Recovery and Reflog
Git recovery patterns using reflog, ORIG_HEAD, fsck, dangling objects, and targeted reset or cherry-pick flows.
Git Config Cookbook
Ready-to-use Git configuration recipes for identity, pull/push policy, aliases, tools, safety, and performance.
Git Revision Syntax
Git revision selectors, ranges, parents, symbolic refs, and object/path addressing.
Git Cheat Sheet
Comprehensive Git commands for day-to-day work, collaboration, history, releases, recovery, and advanced repository workflows.
Recommended next
Docker Swarm Cheat Sheet
DOCKER
Swarm cluster, node, service, and stack commands for container orchestration on Docker Engine.
Docker Buildx Cheat Sheet
DOCKER
Modern BuildKit and Buildx reference for multi-platform builds, cache, secrets, and remote outputs.
Dockerfile Cheat Sheet
DOCKER
High-value Dockerfile instructions, patterns, and build flags for reproducible and efficient image builds.
Docker Cheat Sheet
DOCKER
Comprehensive Docker Engine CLI reference for images, containers, networks, volumes, registries, contexts, and cleanup.