As I’m working with quite a few binary1 files, such as .jpg images, .mp3 tracks and .mp4 videos, .pdf documents, and .zip archives, it’s a best practice to use Git LFS for versioning those files. The initial user setup and instructions on how to use Git LFS for a new repository is described at the project website. However, in my case I need to migrate some exisiting files from plain Git to be tracked by Git LFS.

Git LFS migration

Though the official tutorial expands on adding git-lfs to a pre-existing repo the approach seems to be very complicated. For this reason, I rather follow the approach described in a DevOps blog post. And to tell a long story short, it’s just a matter of these four commands:

cd ~/git-repo-with-large-files
git lfs migrate import --include="*.jpg, *.mp3, *.mp4, *.pdf, *.zip" --everything
git lfs ls-files # list the newly tracked LFS files
git push --all --force # force push all branches to remote

Note: If you are going to use different binary file types, you have to adapt the glob2 pattern parameters in the --include option.


By using the --everything option the tracked files may be replaced by a placeholder pointer, which seems like they are broken. In this case, execute:

git lfs checkout

  1. Binary file in the Wikipedia ↩︎

  2. The glob Linux man page ↩︎

Last updated on