How to shrink the .git folder

git

Solution

Linus Torvalds recommends:

git repack -a -d -f --depth=250 --window=250

This could take a long time for old repos. Consider letting it run overnight.

Note: Do you have a lot of binary files (archives, images, executables) which change often? Those usually lead to huge `.git` folders (remember, Git stores snapshots for each revision and binary files compress badly).

You should not delete all changes older than 30 days (I think it's somehow possible exploiting Git, but really not recommended).

Avoid running `git gc --aggressive --prune`, which performs garbage collection in the repository and prunes old objects. This method is considered bad practice.

Problem

My current base has a total size of approx. 200MB. But my .git folder has an amazing size of 5GB (!). Since I push my work to an external server, i don't need any big local history... How can I shrink the .git folder to free up some space on my notebook? Can I delete all changes that are older, than 30 days?

Original source

Related problems