Learn how to resolve the "file exceeds 100 MB" error when pushing to GitHub by using Git LFS (Large File Storage) to manage large files. This guide will walk you through understanding the error, setting up Git LFS, tracking large files, troubleshooting common issues, and addressing important considerations around Git LFS usage.
Identifying the Error: File Exceeds GitHub's 100 MB Limit
GitHub imposes a strict file size limit of 100 MB per file in repositories. When attempting to push files larger than this, the following error is typically displayed:
error: GH001: Large files detected. The file 'large_file.ext' exceeds GitHub's file size limit of 100.00 MB.This error suggests using Git Large File Storage (Git LFS) to manage oversized files. Git LFS provides an efficient and scalable method for tracking large files without exceeding GitHub's file size limits.
Understanding Git LFS
Git LFS (Large File Storage) is an open-source Git extension designed for managing large files. Here’s how it works:
- Track Large Files as Pointers: Instead of storing large file contents in your Git repository, Git LFS stores pointers in Git, representing the actual files.
- Remote Storage: The actual file data is stored externally in your repository's LFS storage, separate from the repository itself.
- Efficient Handling of Large Files: By maintaining a lightweight repository, Git LFS ensures faster operations and better performance when collaborating via Git.
Using Git LFS resolves the file size limitation by enabling repositories to handle large files seamlessly.
Setup and Installation of Git LFS
To use Git LFS in your repository, you need to install it first. Follow these steps to set it up correctly:
prerequisites
- Git installed on your system.
- Access to a GitHub account and an existing GitHub repository.
steps
Install Git LFS:
- On macOS, use Homebrew:bash
brew install git-lfs - On Windows, download and run the official installer from git-lfs.github.com.
- On Linux, use your distribution’s package manager, e.g.,
aptoryum.
- On macOS, use Homebrew:
Initialize Git LFS: After installation, initialize Git LFS in your repository by navigating to the repo's directory and executing:
bashgit lfs installYou should see confirmation similar to:
Updated git hooks. Git LFS initialized.Verify Installation: Check the installed Git LFS version to confirm it was correctly installed:
bashgit lfs versionExample result:
git-lfs/3.2.0 (GitHub; linux amd64; go 1.17.9)
Tracking Large Files Using Git LFS
Once Git LFS is installed, you need to configure it to track specific file types or individual files.
steps
Define File Types to Track: Use the
git lfs trackcommand to specify the file types you want to track. For example:bashgit lfs track "*.mp4"This will add a configuration entry in a
.gitattributesfile within the repository.Verify the
.gitattributesFile: Ensure changes are reflected in the.gitattributesfile:bashcat .gitattributesExample content:
*.mp4 filter=lfs diff=lfs merge=lfs -textStage Changes: Add the
.gitattributesfile to your repository:bashgit add .gitattributes git commit -m "Add Git LFS tracking for large files"Upload Large Files: Add and commit the large files, then push the changes to the remote repository:
bashgit add large_file.mp4 git commit -m "Add large file" git push origin mainGit LFS will automatically handle the large files during the push.
Common Mistakes and Troubleshooting
Verifying the Integration
To confirm that everything is working as expected:
steps
Push a repository with tracked large files and ensure the upload completes without errors:
bashgit push origin mainCheck the GitHub web interface for LFS-tracked files. These files appear as textual pointers.
Review LFS logs for upload/download status:
bashgit lfs logs lastVerify that the large files were successfully uploaded.
Important Considerations: Bandwidth and History Constraints
FAQ
How do I fix the "file exceeds 100 MB" error when pushing to GitHub?
Install Git LFS, initialize it in your repository with git lfs install, and track large files with the git lfs track command. Once the files are committed, push them to the repository.
What happens if I don’t initialize Git LFS but try to push large files?
Git LFS requires initialization using git lfs install within your repository. Without initialization, files larger than 100 MB cannot be pushed to GitHub, even if tracked.
How do I check my Git LFS storage and bandwidth usage?
You can view your current usage on your GitHub account’s billing settings page. For repositories within an organization, check the organization’s billing settings.