Bitbucket: delete folder from Git history

There is a hard limit of 2 GB when hosting Git on Bitbucket - if this is exceeded, you only have read-only access to the repository. To prevent this, for example, you retroactively remove large folders or files from your commits. But also in other cases (if access data has entered the history or node_modules has slipped onto master again), you have to retrospectively manipulate the history of Git contrary to its nature.


Bitbucket has written a detailed article on this. To go through the whole thing in one case, we first create a new repository:

bitbucket history clean

Then we clone the repository into an empty folder on the local machine:

6ab7686fc508ce87c52b10bb5d01ee51

Now we create two subfolders with files of random content:

6ab7686fc508ce87c52b10bb5d01ee51

We are now pushing on master:

6ab7686fc508ce87c52b10bb5d01ee51

Now we have almost reached the hard limit of 2 GB on Bitbucket:

bitbucket history clean

We can also check this locally (see "size-pack"):

6ab7686fc508ce87c52b10bb5d01ee51

bitbucket history clean

The task now is to retroactively remove "foo" from the repository in order to halve its size. To do this, we first edit the current HEAD and write the folder in the gitignore:

6ab7686fc508ce87c52b10bb5d01ee51

Finally, we remove the folder using the BFG Repo Cleaner (BFG requires a current JRE on the system as a system requirement):

6ab7686fc508ce87c52b10bb5d01ee51

We now see the result locally:

6ab7686fc508ce87c52b10bb5d01ee51

bitbucket history clean

However, the repository size has not yet changed on Bitbucket because the garbage collector has not yet been executed remotely and bitbucket does not execute a "git gc" with every push:

bitbucket history clean

Support also confirms this:

bitbucket history clean

So it is best to send a request directly to support@bitbucket.org to manually run "git gc" in the repository. After a short time the support team also did this:

bitbucket history clean

If you now "freshly" drag the repository to another computer, only 0.9 GB will end up on the disk. If someone still has the 1.8 GB version available locally, a "git pull" followed by "git gc" is sufficient.

Back