Search code examples
gitmacos.git-folder

Why my .git is always bigger when I just write a few code?


This happen twice: I already erased my repo, because of a filesize too big (>100mb), then it always failed when get test in CI/CD GitLab.

So i create the new repo, ... and it happens again: when I check my folder size, the main problem is .git: I dont know what happen and I don't know the solution.
I just have 2 branch (master and develop), and several commits (because it is a new repo)

Then I keep searching the solution , with git command:

git gc --aggresive --prune=now 

but still .git pack so huge, so I really need your help to find this solution, because I don't want to erase my repo again and the problem came again my new repo (so bigg)

gitlab repo information:
gitlab repo information

whatsize folder:
whatsize folder


Solution

  • As commented, make sure your .gitignore will ignore any generated binary.

    Try first to remove anty big files from your past commits, with BFG Repo cleaner ( faster than the native git filter-branch)

    java -jar bfg.jar --strip-blobs-bigger-than 2M some-big-repo.git
    

    Only then you can apply git gc/repack/prune in order for the size to actually go down.

    git gc
    git repack -Ad      # kills in-pack garbage
    git prune           # kills loose garbage