Converting Massive Git Repo's to LFS

I have an old website with a lot of large PDF files commited to my git repository. The repo is 300MB+ and is painful each time I need to clone it locally once in a blue moon to update it.

Thankfully, Github and Bitbucket both support LFS (Large File Storage) now.

Converting your existing repository to LFS is actually super easy using the following.

  1. Back up your repo in case all goes badly.

  2. Install BFG Repo-Cleaner: brew cask install bfg

  3. Install Git LFS: brew update && brew install brew install git-lfs

  4. Clone your existing massive repository as a 'bare' repo: git clone --mirror git@bitbucket.org:username/reponame.git

  5. Move into that new directory: cd reponame.git

  6. Convert those massive PDFs and move to LFS: bfg --convert-to-git-lfs '*.pdf' --no-blob-protection

  7. Not sure what this does: git reflog expire --expire=now --all && git gc --prune=now

  8. Because we used –mirror, this will push ALL branches and tag: git push