Reduce Repo Size on Bitbucket
I’ve realised my repo is coming in at just over 1GB, it seems my
.git folder weighs in at 800MB. Why is this and what are the right ways to go about reducing this?
Any help is appreciated. Thanks in advance!
- Hot-fix during the ongoing release - merge or cherry-pick?
- Attaching VisualSVN Server to an existing repository
- jenkins debugging of SCM
- Reset or revert a specific file to a specific revision using Git?
- Federated (Synced) Subversion servers?
- Git merge commits between branches
2 Solutions collect form web for “Reduce Repo Size on Bitbucket”
Instead of using
git filter-branch manually, I highly recommend using the BFG (https://rtyley.github.io/bfg-repo-cleaner/), since it is much faster and can help you get rid of larger files. The instructions on that page are very easy to follow.
However, note that the BFG removes large files from your .git history only if they are NOT currently committed to your repo. Before you use the BFG, you should
git rm --cached FILENAME
any large files (like large zips as you mentioned above). If you don’t need them anymore, you can just delete them completely. And remember to add
*.zip to your .gitignore!
Your .git folder is bloated somehow, most likely due to git history or old assets:
- They accumulate a very very long history (the project grows over a very long period of time and the baggage accumulates).
- They include huge binary assets that need to be tracked and paired together with code.
- Both of the above.
Here are some ways to remedy it:
Shadow Clone Method
git clone --depth <# of commits of history> <remote-url>.
Filter-branch Method for large binary files or old assets like old PSDs
Run something like
git filter-branch --tree-filter 'rm -rf /path/to/spurious/asset/folder' HEAD. Beware filter-branch can rewrite the history of your commits, thus others who have an older version of your repository will need to clone it again. Warn your coworkers before you do this method!
There are more methods and alternative ways in the atlassian link above.
EDIT: Make sure to create a backup repo of your original repo just in case!