1

I have a Bitbucket repository whereby there's a repo size limit of 2.0 GB. I had created a .gitignore but forgot to add the downloads/documents to it and thus the repo became 8.3 GB.

After I saw the notice in Bitbucket, I quickly ran

$ git rm -r /path/to/docs

After doing the usual git add etc. commands, I got this push error:

repository is in read only mode (over 2 GB size limit).

Learn how to reduce your repository size: https://confluence.atlassian.com/x/xgMvEw.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Which led me to use these commands:

$ du -sh project-root/

This returns:

6.0G project-root

This was a bit worrying as I just removed all of the documents, no way could it be that size. So I ran:

$ du --max-depth=10 -h project-root | sort -n -r

The directory that stands out most is:

5.7G    project-root/.git/objects/pack
5.7G    project-root/.git/objects
5.7G    project-root/.git

In turn, I ran git gc - but this had no effect (or at least in sizing terms).

So how do I reduce the size of my .git/objects directory? I imagine the size was contributed to by the large documents folders, but now they're gone. So how do I "clean" up my git objects?

Community
  • 1
  • 1
treyBake
  • 6,440
  • 6
  • 26
  • 57
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history – phd Jun 04 '19 at 15:32
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+directory+history – phd Jun 04 '19 at 15:32
  • @phd also various search term links aren't constructive to the post or the SO community - to me it's just objects, I wouldn't have searched history at all.. – treyBake Jun 04 '19 at 15:33
  • @phd I must have clicked some other link thinking it was your dupe - because I didn't recognise any answers when I clicked into it again xD either way, the accepted answer is the correct one - as is the one I accepted on this post :) – treyBake Jun 04 '19 at 16:01

2 Answers2

2

If nothing was pushed follow this answer which suggests additional git gc flags for more aggressive pruning.

You can rewrite the repository history and remove large files that should not be committed. This is explained in Reducing the repository size using Git and BFG Repo-Cleaner is suggested:

The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
-1

You should use git reset --hard, which leaves it with only committed files or git clean -d -x -f that removes untracked files, including directories (-d) and files ignored by git (-x).


Take a look on:

How do I clear my local working directory in git?

git-reset

git-clean


Best regards,

Brhaka

Brhaka
  • 1,622
  • 3
  • 11
  • 31
  • I should have mentioned ^^ already done the reset :) but haven't done the clean, will let you know how it goes – treyBake Jun 04 '19 at 15:27