Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce git repository size

Tags:

git

git-clean

I tried looking for a good tutorial on reducing repo size, but found none. How do I reduce my repo size...it's about 10 MB, but the thing is Heroku only allows 50 MB and I'm no where near finished developing my app.

I added the usual suspects (log, vendor, doc etc) to .gitignore already. Although I only added .gitignore recently.

Any suggestions?

like image 814
sent-hil Avatar asked Jan 22 '10 11:01

sent-hil


People also ask

How big is too big for a git repo?

The total repository size will be limited to 10GB. You will receive warning messages as your repository size grows to ensure you're aware of approaching any size limits. Eventually, if the repository size exceeds the limit, you will receive an error message and the push will be blocked.

How do I reduce the size of a .pack file in git?

When you do a Git clone, it will create a copy of the whole repository, this includes the pack file as this is part of the repo too. The only way to reduce the size of the pack file will be by removing contents from your repo.

How do I find the size of my git repository?

To find the size of your . git directory, use du – sh . git. You can use git count-objects -v to count the number of unpacked object files and disk space consumed by them.


1 Answers

Update Feb. 2021, eleven years later: the new git maintenance command (man page) should supersede git gc, and can be scheduled.


Original: git gc --aggressive is one way to force the prune process to take place (to be sure: git gc --aggressive --prune=now). You have other commands to clean the repo too. Don't forget though, sometimes git gc alone can increase the size of the repo!

It can be also used after a filter-branch, to mark some directories to be removed from the history (with a further gain of space); see here. But that means nobody is pulling from your public repo. filter-branch can keep backup refs in .git/refs/original, so that directory can be cleaned too.

Finally, as mentioned in this comment and this question; cleaning the reflog can help:

git reflog expire --all --expire=now git gc --prune=now --aggressive 

An even more complete, and possibly dangerous, solution is to remove unused objects from a git repository

like image 177
VonC Avatar answered Sep 21 '22 15:09

VonC