Repository is over the size limit (4 GB) and will not accept further additions.
Asked by Rafael Berrospi:

remote: Learn how to reduce your repository size: <https://support.atlassian.com/bitbucket-cloud/docs/reduce-repository-size/#Rewind-history-to-undo-large-commits>.  
To <https://bitbucket.org/workspace-id/repo.git>  
! \[remote rejected\] master -\> master (pre-receive hook declined)  
error: failed to push some refs to '<https://bitbucket.org/....git>'

I can not push due to reaching the sit limit of the repo.

How can I delete the big files/folders and push the commit, or i want to add folders to gitignore so I can skip them and free up space, is it possible?

More details:

count: 4875  
size: 1018.52 MiB  
in-pack: 10075  
packs: 3  
size-pack: 3.65 GiB  
prune-packable: 4808  
garbage: 0  
size-garbage: 0 bytes


Answers:
author: Theodora Boudale
body: Hi Rafael,

I ran a git gc for this repo and its size has been reduced to 2.1 GB.

You and your team should be able to push now. However, I would advise reducing the repo's size further, if possible.

You can check this post of mine in a different question with more details:

* <https://community.atlassian.com/t5/Bitbucket-questions/Revert-bitbucket-repository-state-to-one-day-prior/qaq-p/1908360#M76762>

If you decide to proceed with the steps mentioned in that post and rewrite history in the repo with BFG, please keep in mind that the repo's size will get increased again once you push your changes. The repo will then need another git gc for the old commits (prior to history rewrite) to get removed and to get its size reduced. You can let me know here, and I can run another git gc for the repo.

We have a feature request for allowing users to trigger a git gc for their remote repos that you can vote for and add yourself as a watcher:

* <https://jira.atlassian.com/browse/BCLOUD-11593>

Just a heads up, I removed the workspace-id and repo name from your post to protect your privacy.

Kind regards,  
Theodora

comments: author: Rafael Berrospi
body: Good afternoon, what happened was that we have a folder which contains too many static files which we now want to include in the .gitignore and push again.

That way there would be no problem? Or will it go back to the previous size? Please tell me to proceed in this way.


author: Theodora Boudale
body: Hi [@Rafael Berrospi](/t5/user/viewprofilepage/user-id/5115222),

The repo size may go up if you rewrite history and push to Bitbucket. This is because the remote repo will contain both old and new references, and it will need another git gc. I can run it if you let me know after you push, and then the repo's size should get reduced (provided that you pushed a repo of a smaller size).

Please see the following two options I explain below, and ++**take a backup of the repo (a clone with the --mirror flag)**++ before you push any changes so that you can recover the repo if anything goes wrong.

++Option 1++

If that folder is committed to a branch named e.g. feature, and   
- you haven't added more commits to this branch (so, the commit with the large folder is the last one on this feature branch) and  
- you haven't merged this branch into any other branches

then you can:

1. Checkout this branch locally
2. Reset the last commit with  

   ```
   git reset --soft HEAD~1
   ```

3. Push that branch to Bitbucket with  

   ```
   git push --force
   ```

++Option 2++

If the conditions I listed in Option 1 are not met, it's best to rewrite history with BFG. BFG has an option **--delete-folders** that can be used to remove a folder from the repo's history. You can check more details here:

* <https://rtyley.github.io/bfg-repo-cleaner/>

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud