Reduce git repository size

Question

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?

Answer

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


Note that git filter-repo now (Git 2.24+, Q4 2019) replaces the obsolete git filter-branch or BFG: it is a python-based tool, to be installed first.

Joe suggests:

# Find the largest files in .git:
git rev-list --objects --all | grep -f <(git verify-pack -v  .git/objects/pack/*.idx| sort -k 3 -n | cut -f 1 -d " " | tail -10)

Strat filtering these large files:

git filter-repo –path-glob ‘../../src/../..’ –invert-paths –force #or git filter-repo –path-glob ‘.zip’ –invert-paths –force #or git filter-repo –path-glob ‘.a’ –invert-paths –force

git remote add origin [email protected]:…/…git git push –all –force git push –tags –force

How can I make git show a list of the files that are being tracked?

Git reset single file in feature branch to be the same as in master [duplicate]