How to Fix Large File Error in Git Quickly
The large file error in Git happens because Git limits file sizes by default. To fix it, use
Git LFS to manage large files or increase Git's size limits with configuration commands.Why This Happens
Git has a default file size limit (usually 100 MB) to keep repositories fast and efficient. When you try to add or push a file larger than this limit, Git blocks it and shows an error.
bash
git add largefile.zip
Output
error: File largefile.zip is 150.00 MB; this exceeds Git's file size limit of 100.00 MB
The Fix
You can fix this by using Git Large File Storage (Git LFS), which stores large files outside the main repository. First, install Git LFS, then track your large files and push again.
bash
git lfs install git lfs track "*.zip" git add .gitattributes # Now add your large file git add largefile.zip git commit -m "Add large file with Git LFS" git push
Output
Tracking "*.zip" with Git LFS.
Uploading largefile.zip (150 MB)
To origin master
abc1234..def5678 master -> master
Prevention
To avoid this error in the future, always use Git LFS for files larger than 50 MB. Also, add a .gitattributes file early to track large file types. Avoid committing big files directly to Git.
- Use
git lfs trackfor large file extensions. - Set repository size limits and educate your team.
- Use .gitignore to exclude unnecessary large files.
Related Errors
Other errors related to large files include:
- Push rejected due to large files: Happens when remote rejects files over size limit.
- Out of memory errors: When Git tries to process very large files without LFS.
- Slow clone or fetch: Large files slow down repository operations.
Using Git LFS or splitting files can fix these issues.
Key Takeaways
Git blocks files larger than 100 MB by default to keep repos efficient.
Use Git LFS to manage and push large files safely.
Track large file types early with .gitattributes to prevent errors.
Avoid committing big files directly; use .gitignore to exclude unnecessary ones.
Large file errors can cause push rejections and slow repo operations.