Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why my repository is so large after git init + git push --force?

DanielAlievsky June 10, 2025

My repository is too big for BitBucket (~500 MB), I've decided to move it to GitLab. After copying it to GitLab, I've tried to clear the existing BitBucket repository. I don't want to remove it completely, I want to remove all files/history with adding a little README with information about moving to the new address (GitLab).
To to this, I used the following commands:
git init   (in a new folder)
git remote add origin https://bitbucket.org/(my_repository)
git add ...  (my readme file)
git push --force origin master
After this, I don't see any information in the log. But the size of my repository in BitBucket web interface is still ~500 MB, and attempt to clone it creates a very large .git folder
What is the reason? How to REALLY decrease the size of an already unnecessary repository?

3 answers

3 accepted

0 votes
Answer accepted
DanielAlievsky June 12, 2025

At the same time, BFG utility can reduce the size of .git folder, at least in my local copy. But this utility is focused on another problem - removing very large files or some selected file. My problem is more simple: I just want to remove all, without removing the repository itself. How to do this?

0 votes
Answer accepted
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 12, 2025

Hi @DanielAlievsky

Welcome to the community.

I've run Git GC (Garbage Collection) against your repository.

It is now down to 450 MB.

Could you check the same on your end?

Regards,
Mark C

DanielAlievsky June 12, 2025

Thank you very much! It means that I did something wrong, though I consulted here and with ChatGPT. I want to completely remove all my files and history. I already created a new clean repository via git init and also deleted the old branch as Ignacio Ampuero advised. However, the repository size is still 450 MB. What is the reason?
Is there any way to delete all previous commits without full deletion of the repository via BitBucket web interface?

Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 15, 2025

Hi @DanielAlievsky

Perhaps you can you can reset your commits to the first initial commit you've made in the repository. - https://www.atlassian.com/git/tutorials/undoing-changes/git-reset

However, please note that this option is likely going to remove commits history, hence, I suggest taking a backup of your repository locally before proceeding.

Regards,
Mark C

DanielAlievsky June 16, 2025

Thank you for your advice with git reset.
I've checked my repository again and found that there was a very old branch with almost a complete copy of my content. I've switched to that branch and performed git reset, then
git push --force

Now git gc on my computer reduces the size to a few megabytes. Could you also call git gc again on the server side?

Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 17, 2025

Hi @DanielAlievsky

I've gone ahead and run Git GC, the repository size is now 13.8 MB (450.9 MB).

Regards,
Mark C

DanielAlievsky June 18, 2025

Thank you very much!

Like Mark C likes this
0 votes
Answer accepted
Ignacio Ampuero June 10, 2025

Hey!
The way git works is maintaining a history of changes of your repo.
So with your last "empty folder push" you just added a whole repo change from full repo to empty repo, but still just a change, so all the history and repo size is tracked by git.

So what you need to do is the following:

  • Create and move to a new empty orphan branch (start from scratch)
    • git checkout --orphan new_branch
  • Now that you're on the new branch, delete all the repo files from the tracking
    • git rm -rf .
  • Then create your readme file to announce the move
    • vim/nano/whatever_editor README.md
    • git add README.md
    • git commit -m "Repository moved to GitLab"
  • Then now you have a orphan branch with a commit, so you have to delete your old main branch
    • git branch -D master/main/production (choose the name depending of your main branch) 
  • Rename the orphan branch as your new main branch
    • git branch -m new_branch master/main/production (depending on your case)
  • Push the changes to the remote and it will overwrite the old branch with the new empty branch
    • git push --force origin main

That's all the process, it seems long but it has sense because of the way git works and tracks stuff.

Good luck!

DanielAlievsky June 10, 2025

This does not help. The size of repository, shown by BitBucket web interface, is still 634 MB, and attempt to clone it creates .git folder ~450 MB

All that I need is to CLEAR all the history and all files. But I don't want to remove the repository permanently, via BitBucket web interface. Maybe some other user will try to pull, and he will have no any hints why this repository is not available and where it is now.

Ignacio Ampuero June 10, 2025

In fact

That procedure should have done that

  • "All that I need is to CLEAR all the history and all files"
    • Cleaned the branch and history 
    • Just leaving the README

But if you see an empty main branch (with just the README) and cloning generates a heavy .git history. Then the fault is not yours.

There are some cases that repos need manual Garbage Collection, as seen on this discarded feature request
[BCLOUD-11593] Allow users to mark repositories for git gc (BB-13894) - Create and track feature requests for Atlassian products.

But there's also the manual request you can ask to the attlassian team over your repo via request to:

https://support.atlassian.com/contact/.

So they can clean all the dangling objects on your repo's history.

 

DanielAlievsky June 10, 2025

I've started from https://support.atlassian.com/contact/
But the only available option for my free account was asking the question here :)
You think that I need just to wait until the automatic git gc will run? If so, why manual calling "git gc" on my local repository does not reduce the size of .git folder?

Ignacio Ampuero June 10, 2025

Oh, I see
Yes, bitbucket documentation states that they run GC periodically, but depending on repo size and other factors.
For some users sometimes atlassian team goes in and runs GC, via the community forum posts.
You can try with some strict pruning with:

git reflog expire --expire=now --all
git gc --prune=now --aggressive

 for local .git folder cleaning.
And to try a light clone you can use:

git clone --depth=1 bitbucket.com/your_repo

 so it doesn't pull the lingering history of the bitbucket server.

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events