Git Large File Storage (LFS)
Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.
Installation
- On Ubuntu, run
sudo apt install git-lfs - In a given repository, enable LFS by running
git lfs install
Using Git LFS
- Track file types or specific files with the command
git lfs track "*.zip" - Make sure the .gitattributes file is tracked
git add .gitattributes - Pull large files with the command
git lfs pull
Re-import files into LFS
We encountered an issue when creating a private "fake fork" of a repository with LFS files. The LFS pointers copied, but the files themselves did not. We manually added the file into the local repository, but the remote didn't register it as a change, so we need to re-import the files. Here's a complete walkthrough from Chat GPT:
To force-upload a Git LFS file even if the remote already thinks it exists, you need to make Git LFS recalculate the object and push it again. The key is: Git LFS only uploads objects that aren’t in the server’s object store, so if the remote incorrectly thinks it already has them, you must “touch” the LFS objects so Git LFS re-uploads them.
Here are the reliable ways to do that:
✅ Solution: Re-import the file into LFS and push
This tells Git LFS to treat the working copy file as new, even if the pointer already exists in history.
1. Make sure the file is present locally in real form (not pointer form)
Verify it’s not the small pointer:
head -20 path/to/file
If you see text like:
version https://git-lfs.github.com/spec/v1
oid sha256:...
size ...
then it's still a pointer — retrieve it manually or overwrite it with your actual file.
⭐ Method 1: “re-track + re-add” (usually works)
git lfs track "*.whatever" # If not already tracked
git add --force path/to/file
git commit -m "Reimport LFS file"
git push
Forcing the add re-registers the file with LFS and causes a re-upload.
⭐ Method 2 (stronger): Use git lfs clean/smudge to rebuild the pointer object
If Git still refuses to upload:
# Rebuild the LFS object locally
git lfs clean < path/to/file > temp.lfs
mv temp.lfs path/to/file
git add --force path/to/file
git commit -m "Force LFS object regeneration"
git push
This forces LFS to compute a fresh oid, which the remote will treat as missing.
⭐ Method 3 (most reliable): Rewrite history for that file (if allowed)
This guarantees Git LFS uploads the data because the pointer’s SHA changes.
git lfs migrate import --include="path/to/file"
git push --force
This rewrites commits so the file appears “new” to Git LFS.
⭐ Method 4: The nuclear option — prune local LFS cache and force LFS upload-all
git lfs fetch --all
git lfs prune
git lfs push origin --all
This pushes all LFS objects, even historical ones. Useful if many LFS files are missing on the new remote.
✔ Recommended Quick Fix
If you only have one or a few files missing on the remote, the simplest reliable fix is:
git add --force path/to/file
git commit -m "Force reupload LFS file"
git push
This typically bypasses the remote's incorrect “I already have it” state.