0

Problem: Github only allows files smaller than 100MB. Consequently, if you try to push a file over that size, you will get an error when pushing.

I sometimes run into the problem of accidentally adding a big file, e.g. when a debugger created a memory dump, and forgetting about it.

Unfortunately, with the error-message only happening on push, it's possible do multiple commits after the big file was already accidentally committed, and it's a hassle to retroactively remove the big file from the commits.

Question: Is there a way to deny files over a certain size size to be added to the git index, preferably with an error on "git add .", so that file can be added to the git ignore, deleted or handled differently?

Schema
  • 21
  • 2
  • 3
    IIRC, there are no git hooks for `git add`, you have to do this kind of check on `git commit`, i.e. with a pre-commit check. See [this question](https://stackoverflow.com/questions/57718827/why-is-there-no-pre-add-git-hook) for details. – Joachim Sauer Aug 05 '21 at 11:20
  • *Git* does not have this built in. But there is this other program, called `git-lfs`, that takes Git and adds a big old wrapper layer, that *does* have this kind of cleverness built in. You use the wrappers—instead of using raw Git directly—and instead of saving a large file in Git, the wrappers *replace* the large file with a "pointer file". They save the large file data somewhere else, and the repository contains only the pointer files. – torek Aug 05 '21 at 12:31
  • There is a drawback to using Git-LFS, which is: if you aren't aware of it, and use plain Git to clone the repository, everything works, except that *all the large files are replaced with these useless "pointer files"*. Once you realize that you need to use the Git-LFS wrappers instead of base Git, though, you can install git-lfs, install the wrappers, and start using them. – torek Aug 05 '21 at 12:32
  • (I personally don't like using Git-LFS with GitHub, but it is a supported mode of working on/with GitHub. If you don't *need* to store large debugger dumps or whatever, just ... don't do it. I'll note that the tools I use are generally pretty friendly and clever about naming such files, so that `.gitignore` can easily auto-exclude them.) – torek Aug 05 '21 at 12:32

1 Answers1

1

I'm not sure if git has a build-in way to check for this, but this might help your problem:

  • Create your own custom "git add script" using something like Bash. Using git status you could get all the modified file names, check their size and then use git add *filename* to only add the files that fit your criteria and append the other filenames to .gitignore.
Tram13
  • 36
  • 3