This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.
Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.
Of course, you can just download it directly to the hooks in an existing git repo.
The default limit is max 5MB per file. If you feel that your commit is a special case, you can always override the limit with:
GIT_FILE_SIZE_LIMIT=42000000 git commit -m "This commit is allowed file sizes up to 42MB"
- pre-commit : The hook itself
- install.sh : Installs this hook to your git template directory.
You can use in two ways.
- Directly as the pre-commit hook in your .git/hooks folder.
- With Husky by updating your package.json with:
"husky": {
"hooks": {
"pre-commit": "sh ./some-path/pre-commit-prevent-large-files.sh"
}
}
To install this for all future repositories
curl -L https://gist.github.com/danmackinlay/6e4a0e5c38a43972a0de2938e6ddadba/raw/install.sh | bash
For just the current one (erasing any existing pre-commit hooks)
curl -L https://gist.github.com/danmackinlay/6e4a0e5c38a43972a0de2938e6ddadba/raw/pre-commit > .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
Based on @kiwidamien's original gist here.
Adapted from: https://gist.github.com/benmccallum/28e4f216d9d72f5965133e6c43aaff6e
Help from this stackoverflow question.
This version is based on @guysmoilov’s fork which adds a neat isntaller script.
pre-commit is "a framework for managing and maintaining multi-language pre-commit hooks" and has a hook you can plug-in called: check-added-large-files
. pre-commit is built with Python though, so you'll need Python installed.