Git Lifecycle Hooks
For too long time I've ignored this powerful tool that I use for
local pre-commit formatting and checks
add branch name to a commit message
Implement your own hook
The folder .git/hooks
of every git repo contains some sample
pre-commit.sample
pre-push.sample
prepare-commit-msg.sample
A hook implementation has to have a specific name (e. g. pre-commit
) and needs to be executable. You can either/or
create it manually
create a
~/.git-templates/hooks
folder containing all hooks that should be copied duringgit init
git init
is not only used for the initial git-repo setup but you can use it anytime when you want to have the~/.git-templates
applied
For the pre-commit hook there was a framework (Plugin-based) implemented that gets contributions for a wide range of technologies and use-cases (see below).
Pre-Commit Hook Project
Here's an example how it could look like:
https://github.com/mattlqx/pre-commit-search-and-replace/blob/main/.pre-commit-config.yaml
Install
Setup
adding
.pre-commit-config.yaml
](.pre-commit-config.yaml) to the root of your repocd my-git-repo
pre-commit install
this adds
.git/hooks/pre-commit
implementation based on.pre-commit-config.yaml
into the repository
Manual Usage
pre-commit run --all-files
Auto Usage
Every git commit
will FIRST check and change all files (depending on which hooks are enabled). If there is no changed file it will report that it was running like that:
Update
pre-commit autoupdate
will change the .pre-commit-config.yaml
Last updated
Was this helpful?