Search code examples
gitbfg-repo-cleanergit-gc

Test Git repo size reduction after deleting a branch


Is there any way I can test how the deletion of several branches will affect the size of that git repo. I have a git repo with 10 lived branches and hundreds of feature (short lived branches).

The repo is very large and slow to clone. GitLab shows 1.4 GB as the total size, git-sizer shows a blob total size of 8.4 GB.

I have tried tools such as BFG Repo Cleaner to remove unwanted history, but I've only managed a reduction of 1.4 to 1 GB which is not really sufficient.

My strategy split my repo in 2 and also to use multiple forks to separate streams of work. I will also add push extension and size restriction in GitLab to stop pushing of junk. We've had problems with .rar, .zip, .jar files, personal backups mistakenly pushed etc. However I also want to know if I can retain the history of my long lived branches. So my questions:

  1. Is it possible to see how much the size would be reduced if I deleted all the short lived branches?
  2. Can this be achieved locally?
  3. Or do I just have to duplicate everything to a test repo on GitLab and delete the branches on this test repo?

Solution

  • Answering your three questions, I'd say that yes, it is possible to check this locally. (dependind on what you mean by if I deleted all the short lived branches, I'll assume they are not merged).

    You can clone your repo, create local branches for the branches you want to keep, remove the remote, and gc aggresively.

    However I don't think that'll help as much as using BGF repo cleaner to remove large binary files. If you need to track said binary files, you should switch to git-LFS for those files.

    Your experience with BGF seems strange, I'd expect a much better reduction if you cleaned your repo properly.