Sub topic 3
Moving Existing Files into Git LFS
Assume you know clone, add, commit, push, branches, remotes, and .gitattributes. This chapter focuses on files already committed to Git history.
Move Existing Files with `git lfs migrate`
git lfs migrate import rewrites commits so matching files become LFS pointer files. The real content moves to LFS storage when you push.
git lfs migrate import --include="*.psd" --everything
git push --force-with-lease --allThis changes commit IDs because the contents of old commits change. Coordinate with everyone using the repository before pushing rewritten history. Make a backup or test on a fresh clone first.
The --include pattern can target paths or extensions. Review the rewritten repository before pushing, especially when several branches or tags exist.
Server Storage and Bandwidth
Git LFS uses storage and bandwidth outside ordinary Git hosting. A hosting provider may impose quotas, file-size limits, or separate billing. A successful Git push does not always mean every LFS object uploaded successfully. Check the provider's LFS settings and quota reports.
Lock Binary Files
Binary files such as .psd files cannot be merged usefully. If the server supports LFS locking, mark files as lockable:
git lfs track --lockable "*.psd"
git add .gitattributes
git commit -m "Make design files lockable"
git lfs lock design/logo.psd
git lfs locks
git lfs unlock design/logo.psdLocking reserves a file on the server. It coordinates edits, but it does not replace commits, reviews, or backups.
Use LFS in CI
Continuous integration (CI) jobs need the real files, not only pointers. With GitHub Actions, enable LFS during checkout:
steps:
- uses: actions/checkout@v4
with:
lfs: trueOther CI systems may require git lfs install followed by git lfs pull.
Troubleshooting and Alternatives
A pointer file in the working tree usually means smudge downloading was skipped or the LFS object is unavailable. Run:
git lfs pull
git lfs fetch --all
git lfs fsckCheck the remote URL, authentication, server quota, and the output of git lfs status. A missing object may require restoring it from another clone or backup.
Use ordinary Git for small binaries. Use an artifact repository, object storage, or a dataset-specific tool when files are generated, published independently, or too large for your LFS provider.
Exercise
Why does migrating existing files require a coordinated force push?
Show answer
Migration rewrites historical commits, which changes their commit IDs and makes the old remote history diverge.