Skip to content

Instantly share code, notes, and snippets.

@akkartik
Last active July 5, 2017 17:40
Show Gist options
  • Save akkartik/276b24044383f1578df5 to your computer and use it in GitHub Desktop.
Save akkartik/276b24044383f1578df5 to your computer and use it in GitHub Desktop.
A git pre-commit hook to not permit commits with files larger than 100MB
#!/bin/sh
#
# Github won't permit files larger than 100MB (https://help.github.com/articles/working-with-large-files);
# don't wait to realize this until you try to push a bunch of commits.
git diff --cached --name-only |
while read file
do
if [ $(du -m $file |cut -f 1) -ge 100 ]
then
echo Files too big: $file and maybe others
exit 1
fi
done
# Don't add any other commands here. The 'exit' above will only exit the
# pipeline, and the exit status of the entire script is the exit status of the
# final command. I hate sh/bash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment