git Won't Push

Recently I was working on the Magento installation at work. No, I don’t recommend Magento, but anywho, it’s a large repository. Magento large. In the future I’m just going to use the word Magento in place of anything that is freaking huge. You should too. Git has worked just fine with over 20 commits on the repo since I started. But a few days ago I added a folder with about 70 or so large static files, images, videos and so forth. I was able to add and commit them just fine but when I tried to push the changes I got this error.

error: pack-objects died of signal 15 error: pack-objects died with strange error

Nothing like strange errors to wake you up in the morning. Crap. That sucks. I looked around at several different ways to get that folder out of my commit, but not delete it! Everything I tried still wanted to push those files to the repo and resulted in the same error. Finally I found a way to have git go through each commit and remove any reference to that folder without removing the folder. I was then able to add the folder to my .gitignore file, commit that and push normally. Whew!

Here is how it’s done:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r media/newassets' --prune-empty --tag-name-filter cat -- --all

In this case it will step through each commit and remove the references to the folder in media/newassets, keeping any other files or changes made in that commit and removing entirely a commit that only referenced that folder or files in it.


Like most things there are other ways to get this done but not in a single, simple command.