Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing .git file size

Tags:

git

My .git file has grown to 229Mb and I wondering what the best way to cut down the size is. I know about git gc and have been using it a fair amount. I'm not totally sure about how git works, but I know that there is packaged information in there that I no longer need. Like, I know I no longer need the first five branches saved. Is there a way to completely erase really old branches or commits or something like that?

like image 976
DavidP6 Avatar asked May 28 '10 00:05

DavidP6


4 Answers

If you want to keep your (reachable) commit history intact, then expire, repack, prune, and garbage collect:

git reflog expire --expire=0 --all
git repack -ad
git prune 
git gc

This should be the minimal size you can get your repo and keep your commit history.

If not, i.e., you want or do not mind starting afresh with the current state of the repo as the initial commit, then Peter Tillemans' approach will do it.

like image 175
Jeet Avatar answered Oct 16 '22 00:10

Jeet


You have some techniques in "Reduce git repository size", but I mention also in it than git gc alone can increase the size of the repo!

So some filter branch (also referenced in that question) can be needed, if nobody is actively pulling from your repo.

One factor which tends to increase rapidly the size of a Git repo is the versioning of too many binaries. It is one of Git limits, so try to:

  • version such large object in their own Git repo, referenced as submodules
  • or version them in an external repository made for deliveries, like a Maven repository (i.e. "not in a Git repo")
like image 44
VonC Avatar answered Oct 16 '22 01:10

VonC


I'd do a bit of garbage collecting with git gc

like image 20
Rob Wilkerson Avatar answered Oct 16 '22 01:10

Rob Wilkerson


The easiest would be to do a

git clone --depth 1 your_old_repo

on a new location and then swap it back in place.

see also git faq

like image 22
Peter Tillemans Avatar answered Oct 15 '22 23:10

Peter Tillemans