The pre-commit
git hook tests branch name against a text pattern.
If commits don't match the pattern, they will error and contributors will have the opportunity to rename the branch before trying to commit again.
The example pattern ensures branch names are:
- scoped by type of change and team owner
- types
feat|fix|spike|chore|docs|test|build
- lowercase team name/initial/acronym (hyphenated), e.g.
mobile-team
- any valid name under scope (up to your convention)
First update .git/config
to set a path for hooks.
This is so your hook file can be committed to source control.
[core]
hooksPath = .githooks
Then copy the hook file to .githooks/pre-commit
.
See matching and mismatching branch name examples on Regexr.