Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Git consume less disk space?

Tags:

git

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.

like image 646
Joao Trindade Avatar asked Sep 09 '09 10:09

Joao Trindade


People also ask

Does git take up a lot of space?

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.

How big is too big for a git repo?

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.


1 Answers

There are a few suggestions I can offer:

  1. 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.

  2. 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.

  3. 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.

  4. 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).

  5. 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".

like image 51
Jakub Narębski Avatar answered Oct 11 '22 13:10

Jakub Narębski