Skip to content

Instantly share code, notes, and snippets.

@GenevieveBuckley
Last active August 23, 2019 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GenevieveBuckley/d8f20191087d0848645f158d63d0197f to your computer and use it in GitHub Desktop.
Save GenevieveBuckley/d8f20191087d0848645f158d63d0197f to your computer and use it in GitHub Desktop.
Git pre-commit hooks with black and flake8
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: flake8
- id: check-ast
- id: check-merge-conflict
- id: no-commit-to-branch --branch master
@GenevieveBuckley
Copy link
Author

How to use git pre-commit hooks

Make sure you have black, flake8, and pre-commit installed into your environment.

pip install black
pip install flake8
pip install pre-commit

Then create .pre-commit-config.yaml in the root directory of your repository and run:

pre-commit install

This will put all your pre-commit hooks into .git/hooks/ and make sure they are enforced before every commit.

Further reading

https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment