What is the best way for git to consume less disk space?
I'm using git-gc on my repositories (which does help, especially if there have been many commits since it was cloned) but I would like suggestions if there is any other command to shrink the disk space used by git.
To give you some examples: Git itself is 222MB, Mercurial itself is 64MB, and Apache is 225MB. In bitbucket, there are two git storage limits; Soft limit and Hard limit. Soft Limit (1GB) : You will reach soft limit if your repository size reaches 1 GB. Bitbucket will notify the users about the storage limit.
Git has no limit on repo size, but repository managers typically do cap repository sizes unless you work out special arrangements with them: Bitbucket – 2 Gb, GitHub – 2 Gb with provisions for 5 Gb, GitLab and Azure DevOps – 10 Gb.
There are a few suggestions I can offer:
Delete no longer used branches. They can pin some commits that you don't use and would never use. Take care however to not delete branches that you would later need (perhaps for review, or for comparison of failed effort). Backup first.
Check if you didn't commit some large binary file (perhaps some generated file) by mistake. If you have, you can purge it from history using "git filter-branch"... well, if you didn't share the repository, or it is worth aggravating other contributors to rewrite history. Again: backup first.
You can prune more aggressively, discarding some safeties, bu using git gc --prune=now
, or low-level git prune
. But take care that you don't remove safeties and backups (like reflog) that you need minute after compacting.
Perhaps what enlarges your repository are some untracked files in working directory. There "make clean" or "git clean" might help (but take care that you don't remove some important files).
Most safe of all those suggestions: you can try to pack more aggressively, using --depth
and --window
option of low-level git-repack
. See also Git Repack Parameters blog post by Pieter de Bie on his DVCS Comparison blog, from June 6, 2008. Or "git gc --aggressive
".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With