git out of memory errors – git repack

git out of memory errors – git repack

Occasionally when using git (particularly with large repositories) you might come across an error that looks a little bit like this:

Code block    
remote: Counting objects: 506, done.
remote: fatal: Out of memory, malloc failed (tried to allocate 342222798 bytes)
remote: aborting due to possible repository corruption on the remote side.
fatal: protocol error: bad pack header

It means the remote server has run out of memory while packing objects on the server ready to send down the wire, and has aborted the pull request mid-way.  If you know you’ve got some particularly massive files in your repository that you didn’t really need there, you could rewrite history and get rid of them, but chances are you just need to do a little maintenance on your remote repository.

Connect to your remote server, and find the repo in question, then just run the following:

Code block    
git repack -a -f -d

Now you should be able to pull your repo again, with everything already packed on the server.

Obviously, you can find more about those options with:

Code block    
man git-repack

Tags: , , ,

Leave a Reply?