This Git LFS error occurs when files that should be tracked by LFS (per .gitattributes) were committed directly to the repository instead of as LFS pointer files. The fix involves re-adding files to LFS or using git lfs migrate.
Git Large File Storage (LFS) works by storing large files on a remote server and keeping only small "pointer files" in your Git repository. These pointer files contain metadata including the file's SHA-256 hash and size, which Git LFS uses to fetch the actual content when needed. When you see this error, it means there's a mismatch between what your `.gitattributes` file says should be tracked by LFS and what's actually stored in the repository. The files matching your LFS patterns contain the full binary content instead of the expected pointer format: ``` version https://git-lfs.github.com/spec/v1 oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393 size 12345 ``` This typically happens when files were committed before LFS tracking was configured, when a colleague committed files without LFS installed, or when files were added through a GUI or IDE that doesn't respect LFS filters. The error is Git LFS's way of protecting you from accidentally pushing large files directly to your repository.
First, identify which files are causing the issue:
git lfs statusThis shows files that LFS is tracking and any that have issues. Also check what patterns are configured:
cat .gitattributesVerify LFS is installed and configured:
git lfs version
git lfs envThe git lfs migrate import command converts files to LFS pointers. For files only in recent commits without rewriting history:
git lfs migrate import --no-rewrite "path/to/file.ext"This creates a new commit moving the file to LFS. Verify it worked:
git lfs ls-files | grep "file.ext"You should see the file listed in the output.
If you prefer more control, manually remove and re-add the files:
# Remove the file from Git's index (keeps the working copy)
git rm --cached path/to/file.ext
# Re-add the file (LFS filter will process it)
git add path/to/file.ext
# Commit the change
git commit -m "Convert file to Git LFS"For multiple files matching a pattern:
git rm --cached "*.psd"
git add "*.psd"
git commit -m "Convert PSD files to Git LFS"To re-evaluate all files against LFS filters:
# Remove all files from index
git rm -r --cached .
# Re-add all files (LFS filters will be applied)
git add .
# Commit the changes
git commit -m "Fix LFS pointer files"Warning: This creates a large commit. Review with git status before committing.
If you need to remove the original large files from history entirely to reduce repository size:
git lfs migrate import --include="*.psd,*.zip,*.tar.gz" --everythingWarning: This rewrites Git history. All team members will need to re-clone or carefully rebase. Use with caution on shared repositories.
For a specific set of commits:
git lfs migrate import --include="*.psd" --include-ref=HEAD~10..HEADAfter fixing the pointer files, clean up to reclaim space:
# Expire old references
git reflog expire --expire-unreachable=now --all
# Run garbage collection
git gc --prune=now
# Verify LFS files are correct
git lfs fsckPush your changes to the remote:
git push origin mainIf you rewrote history, you'll need force push (coordinate with your team first):
git push --force-with-lease origin mainThe --force-with-lease flag is safer than --force as it prevents overwriting others' work.
Ensure all team members have Git LFS installed:
git lfs installAdd a pre-commit hook to catch untracked files. Create .git/hooks/pre-commit:
#!/bin/sh
git lfs status --porcelain | grep "^?" && {
echo "Error: Files not tracked by LFS that should be"
exit 1
}Make it executable:
chmod +x .git/hooks/pre-commit### Case Sensitivity on Cross-Platform Teams
Git LFS v3.6.0+ changed how file matching works. If your team uses both macOS/Windows (case-insensitive) and Linux (case-sensitive), use case-insensitive patterns in .gitattributes:
*.[jJ][pP][gG] filter=lfs diff=lfs merge=lfs -text
*.[pP][nN][gG] filter=lfs diff=lfs merge=lfs -text### LFS in CI/CD Pipelines
CI runners may not have LFS installed or configured. For GitLab CI:
variables:
GIT_LFS_SKIP_SMUDGE: "1" # Skip LFS during clone for speed
before_script:
- git lfs install
- git lfs pullFor GitHub Actions:
- uses: actions/checkout@v4
with:
lfs: true### Checking LFS Pointer Format
A valid LFS pointer file looks like this:
version https://git-lfs.github.com/spec/v1
oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393
size 12345If you open a file and see this text instead of binary content, LFS checkout hasn't run. Use git lfs checkout to fetch the actual files.
### Multiple LFS Installations
If you have both system-level and Homebrew Git LFS on macOS, you might have version conflicts. Check with:
which git-lfs
git lfs versionEnsure your PATH prioritizes the correct installation.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git