I want to add to all these answers that you can also just use a git hook to have something more automatic (or less human-error prone) like this:
cat .git/hooks/pre-commit
#!/bin/bash
echo "automatically ignoring large files"
find . -size 5M | sed 's|^\./||g' >> .gitignore
cat .gitignore | sort | uniq > .gitignore
git diff --exit-code .gitignore
exit_status=$?
if [ $exit_status -eq 1 ]
then
set +e
for i in `cat .gitignore`
do
set +e
git rm --cached $i
done
git add .gitignore
git commit .gitignore --no-verify -m"ignoring large files"
echo "ignored new large files"
fi
It is pretty brute force and the downside is that in case there were new large files added by the git hook, the origin commit fails because the state (hash) changed. So you need to execute another commit to actually commit what you have staged. Consider this as a feature telling you that new large files were detected ;-)