Moving Git Large Files to Git LFS in Bitbucket Cloud
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
This document provides detailed instructions for utilizing Git LFS migrate to convert historical large files in a repository to Git LFS in Bitbucket Cloud. Git LFS migrate serves as an alternative to the BFG tool, particularly when repositories exceed size limits causing the BFG LFS migration to fail with "java.io.IOException: In-memory buffer limit exceeded" errors and similar issues.
Disclaimer:
Git LFS migrate completely rewrites the Git history for the repository. The entire migration process can take a while, during which time you and any members of your workspace should avoid working with the existing repository.
It is essential to perform all conversions with a backup of the mirror-cloned repository and conduct testing in a separate environment/repository.
For more details on Git LFS migrate, refer to the official Git LFS documentation.
Please note that the provided commands and instructions are specific to Bitbucket Cloud. If you are using a different Git hosting platform, refer to their documentation for platform-specific instructions.
Solution
Step 1: Clone the repository as a mirror:
git clone --mirror git@bitbucket.org:<username>/<repo-name>.git
Step 2: Prioritize the safety of your data by creating a backup of the <repo-name>.git
folder. This safeguards your data and minimizes the risk of unintended consequences.
Step 3: Install Git LFS:
cd <repo-name>.git
git lfs install
Step 4: Import the large files to LFS:
git lfs migrate import --include='.py,.jpg,*.png,jupyter_notebook,scripts/file_handling' --everything
Note:
Specify only the file extensions that you need to migrate to LFS storage.
Step 5: Clean up the repository's reflog and aggressively prune unused objects:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
Step 6: Force push the changes to the remote repository:
git push --force