My repo size is 2.15GB how i can reduce it
Asked by Ahmad Kabeer Shaukat:

I have applied several methods based on documentation in the URL provided by bitbucket as a repo size warning message   

I tried below   

To be safe I forked the repo to my account and applied the below code so that   
i could see the solution works or not but to no avail even this solution increased by repo size to 2.19  

<br />

but could not find any   
git clone git@bitbucket.org:workspace-id/repo.git cd crepo/ git checkout dev \&\& git pull git gc java -jar ../bfg-1.14.0.jar --strip-blobs-bigger-than 20M git reflog expire --expire=now --all \&\& git gc --prune=now --aggressive


Answers:
author: Nikola Perisic
body: Welcome to the community [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350) !

I hope this page resolves your issue: <https://support.atlassian.com/bitbucket-cloud/docs/reduce-repository-size/>

comments: author: Ahmad Kabeer Shaukat
body: i tried everything on this page   

i created a temp repo and pushed all my actual repo content   
and it shows a size of 7.9 MB   

however even after deleting all my tags and a lot of branches I was unable to reduce my git repo size


author: Ahmad Kabeer Shaukat
body: git ls-tree -r --long HEAD \| sort -k 4 -n -r \| less  
this commands list all files with ascending order to there file size and there is 4 files above 20 MB in this list


author: Ahmad Kabeer Shaukat
body: [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5166624)


author: Theodora Boudale
body: Hi [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350),

If you rewrite history and push to the remote, its size will increase because the remote repo will have both old references (before history rewrite) and new ones (after history rewrite). A git gc is needed on the remote repo to remove any old references. While end users can run a git gc on their local repo, they can't trigger a git gc on the remote repo.

I see that you have deleted the fork you created. Please let me know when you push the BFG changes to the repo it was forked from, and I can run a git gc for it.

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

Kind regards,  
Theodora

comments: author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) Thanks for your kind response.  

Is there anything that can be done from your side because I failed to reduce the repo size   
either it could be guidance or some direct help   
the goal is to reduce repo size we want to remove all history except for the last month


author: Theodora Boudale
body: Hi [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350),

After you push your changes with BFG to a Bitbucket repo, we need to run a git gc on this repo from our side for the change in size to be reflected.

I have the following suggestions:

**1.** I see that you are running the BFG in a regular clone of the repo. Please run it on a mirror clone as per the instructions on the BFG page <https://rtyley.github.io/bfg-repo-cleaner/>

You can take a mirror clone with

```
git clone --mirror git@bitbucket.org:workspace-id/repo.git
```

**2.** After you follow the steps on the mirror clone, create an empty Bitbucket Cloud repo (no .gitignore, no README). Push to this empty repo, and then inspect the size and if the repo is in good shape.

If it is, then push to the repo your team normally uses.

**3.** Afterwards, please post a message here so I can run a git gc on the repo (not the new one, the one your team normally uses)

Kind regards,  
Theodora


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) available for guidance?


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) removed all the branches   
deleted all commit history using the below set of instructions   

git checkout --orphan last  
git add -A git commit -am "fresh init"  
git branch -D dev  
git branch -m dev  
git push -f origin dev  

<br />

but still repo size has increased


author: Theodora Boudale
body: Hi [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350) ,

I can run a git gc for the repo, this may help reduce its size.

Which is the repo where you pushed these changes? Is it the one named v\*\*\*\*\*ces or the one named v\*\*\*\*ces-fork?

Kind regards,  
Theodora


author: Ahmad Kabeer Shaukat
body: Yes please run GC on v\*\*\*\*\*ces  
not v\*\*\*\*ces-fork


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) leave a comment after you run GC ...so that I could check


author: Theodora Boudale
body: Hi [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350),

I ran a git gc, but the repo's size remains is still 2.2 GB.

I would like to ask if you could check the following:

Take a mirror clone of the repo with the command

```
git clone --mirror <repo_url>
```

Then, navigate to the directory of the mirror clone and run

```
git count-objects -Hv
```

What is the output that you see?

If the sum of the fields **size** and **size-pack** in the output is less than 2.2 GB, then it is possible that some of the old references are still part of certain PRs in the repo.

Please let me know what output you see and I can then inform my colleague who is handling your support ticket to investigate.

Kind regards,  
Theodora


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ok I will check that  
secondly the repo size in the bitbucket page is showing 2.15 which initially was when I started to solve the issue   
but I want to let you now that   
all branches have been deleted except dev which is forcibly pushed by creating an orphan branch to remove or clean all previous commit history hence no PRS exists on repo


author: Ahmad Kabeer Shaukat
body: ![Screenshot 2024-03-18 at 2.56.15 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/312654iD992D7B235589915/image-size/large?v=v2&px=999 "Screenshot 2024-03-18 at 2.56.15 PM.png")


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)


author: Theodora Boudale
body: Thank you for the info, [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350).

Even if you deleted all branches, some refs may still exist in older PRs of the repo.

I have informed my colleague who is handling your support ticket that the size of the mirror clone is smaller, and he is going to check if it is PR refs that take up so much space.

You will receive an update from my colleague in the support ticket you created.

Kind regards,  
Theodora


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) Thanks


author: Ahmad Kabeer Shaukat
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) creating and deleting a branch will automatically run GC behind the scenes   
am I correct ?


author: Theodora Boudale
body: Hi [@Ahmad Kabeer Shaukat](/t5/user/viewprofilepage/user-id/5440350) ,

Every push to a repo will trigger a git gc but with different options and arguments depending on several conditions.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud