Migrating Git Repository to LFS

January 6, 2019 VCS

Git Large File Storage (LFS) replaces large (usually binary) files such as images with text pointers inside Git, while storing the file contents on a remote server like GitHub. This article shows how to make an existing git repository use Git LFS for the necessary types of files.

Initial setup

Install required packages:

$ sudo dnf install git-lfs -y

Add binary files to track:

$ git lfs track '*.png'
$ git add .gitattributes
$ git commit -m "Use LFS for *.png"


Migrate existing binaries to LFS (WARNING! This overwrites repository history!):

$ git lfs migrate import --include="*.png" --include-ref=refs/heads/master

Check LFS objects:

$ git lfs ls-files

Push changes to remote (may require force push):

$ git push


Clear old references:

$ git reflog expire --expire-unreachable=now --all
$ git gc --prune=now

Known issues

GitHub Pages cannot serve LFS files yet. See git-lfs/#1342.

comments powered by Disqus