Git LFS hooks for pre-commit
pre-commit
documentation: https://pre-commit.com/index.html
Git Large File Storage (LFS) page: https://git-lfs.github.com
Add the following to your .pre-commit-config.yaml
file:
- repo: https://github.com/KAUTH/git-lfs-hooks
rev: '' # Use the SHA or tag that you want to point to
hooks:
- id: post-checkout
- id: post-commit
- id: post-merge
- id: pre-push
-
Since running
git lfs install
typically installs all related hooks, we also advise using all of them in yourpre-commit
configuration file. -
The version in .version corresponds to the supported Git LFS version.
Git LFS installs a series of useful Git hooks supported by specific commands that are called from the corresponding hook.
Listing the command documentation of the Git LFS hooks' implementation:
- https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-post-checkout.adoc
- https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-post-commit.adoc
- https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-post-merge.adoc
- https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-pre-push.adoc
If pre-commit
hooks (the same type as the ones used by Git LFS) are being used in a repository
and we install Git LFS afterward, the latter tool will not be able to automatically install
its hooks.
With this repository, the pre-commit
framework and Git LFS can both use the hooks
with no issues.
For the inverse, meaning if Git LFS is already installed and we want to
start using the pre-commit
framework later, pre-commit
is able to migrate
the existing hooks (https://pre-commit.com/#running-in-migration-mode). In this
scenario, this solution is not necessary.
In any case, these hooks can be used to avoid having the Git LFS hooks in migration
mode and can give a holistic view of the available hooks from the .pre-commit-config.yaml
file.