LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-hooks

Scripts triggered at Git workflow points

TLDR

Create pre-commit hook
$ echo '#!/bin/sh' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
copy
List available hooks
$ ls .git/hooks/*.sample
copy
Enable sample hook
$ mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
copy

DESCRIPTION

Git hooks are scripts that run automatically at key points in the Git workflow. They enable automation of tasks like linting, testing, and commit message validation.Hooks are stored in .git/hooks/ and must be executable. Common hooks include pre-commit (before commit), prepare-commit-msg (edit message), commit-msg (validate message), and pre-push (before push).

CONFIGURATION

.git/hooks/

Default directory containing hook scripts for the repository. Scripts must be executable.
core.hooksPath
Git config variable to override the hooks directory (since Git 2.9). Set with `git config core.hooksPath <path>`.

HOOK TYPES

Client-side hooks:

$ pre-commit         Run before commit
prepare-commit-msg Edit commit message template
commit-msg         Validate commit message
post-commit        After commit completes
pre-rebase         Before rebase starts
post-checkout      After checkout or switch
post-merge         After merge completes
pre-push           Before push
copy
Server-side hooks:
$ pre-receive        Before accepting push
update             Per-branch pre-receive
post-receive       After push completes
post-update        After all refs updated
copy

INSTALL

sudo apt install git
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

CAVEATS

Hooks are not version-controlled in .git/hooks. Use tools like Husky or pre-commit to share hooks. Hooks can be bypassed with --no-verify. Keep hooks fast to avoid workflow friction.

SEE ALSO

git(1), git-commit(1), husky(1), pre-commit(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid