Git -- add all files that are smaller than X megabytes

git

Solution

There are no flags to `git` that will do what you want. However, there are a lot of other utilities available that would work just fine...such as the `find` command. To add all files smaller than 4 MB:

find * -size -4M -type f -print | xargs git add

This assumes that you have no filenames containing spaces (e.g., "my important file"). If you have such files, then:

find * -size -4M -type f -print0 | xargs -0 git add

UPDATE: Note that I've replaced `.` with `*` here, because otherwise it will find (and try to add) things in your `.git` directory, which is not helpful.

Problem

I'm using git to manage a non-coding-project folder that has some large files scattered all over the place. I'm not interesting in moving the files around as they are not mine, but I know git has issues with very large files (in Linus's words, "we suck at it") and I'd like to avoid those performance issues as much as I can. So here I am, just ran `git init` and about to hit enter on `git add -A` but stop just before I do. I'd like to try to add a flag to `git add` that selects only certain files. I'm not wanting to be prejudiced based on extension, only based on size. Can `add` or my `.gitignore` file do that?

Original source

Related problems