I was getting a
Git cannot allocate memory error when using bundler during a Capistrano deployment.
Although my current app was less than 1.5 MB, my
.git file was over 60 MB, because of some large files I had accidentally added to version control. Even though I had long since deleted those big files from my working directory, Git still kept a record of them in history, thus the bloated
.git file. I fixed the error by shrinking my git repository using these two resources as a guide:
Honestly I am still not clear on why this solution worked. I read somewhere that git loads the whole repository into memory, so if the repository is big, then memory may run out. And bundler probably uses git to get the gems…
Lesson learned: it feels like a hack to use git to ‘rewrite history’, and I don’t think it can possibly be a best practice, so the real solution is to be much more careful in the first place about what files are allowed to make it into version control. Especially when using carrierwave for large file uploads, and using ttf files of Chinese fonts!