Sometimes we accidentally forget to remove unwanted backup zip files or we might have some of the large size files available in the git local repo. Now when we try to commit and push this code to the git, it starts throwing an error.
To resolve the issue of exceeding the file size limit on GitHub, you have a few options:
Solution for git large file issue
Remove the large file:
If the file
abc.zip is not essential to the repository or if it can be regenerated or downloaded separately, you can consider removing it from the repository altogether. This will immediately resolve the issue.
You can use the following steps:
- Delete the file from your local repository.
- Commit the deletion:
git commit -m "Remove large file abc.zip".
- Push the changes to GitHub:
git push origin
Git Large File Storage (Git LFS):
If the file is necessary to keep in the repository, you can use Git LFS to manage large files separately. Git LFS replaces the large file with a pointer to the file, while storing the actual file content on a remote server.
Here’s how you can set up Git LFS:
- Install Git LFS by following the instructions for your operating system:
- Initialize Git LFS in your repository:
git lfs install
- Track the large file(s) using Git LFS:
git lfs track "path/to/abc.zip"
- Commit and push the changes:
git add .gitattributes git add abc.zip git commit -m "Add large file abc.zip" git push origin <branch-name>.
Make sure to replace <branch-name> with the appropriate branch name.
Git Large File Storage (LFS) with alternative hosting:
If you prefer not to use Git LFS, you can consider hosting the large file elsewhere, such as a cloud storage service (e.g., Google Drive, Dropbox), and provide a download link or instructions in your repository’s README file for others to access the file.
- Upload the
abc.zipfile to a cloud storage service.
- Update your repository’s README file with instructions on how to download the file or provide a direct download link.
- Commit and push the changes to GitHub:
git add README.md (or the appropriate file), git commit -m "Update README with file download instructions" git push origin
Still encounter with the error even after removing the large file
If you have removed the large file
abc.zip from your local repository and committed the changes, but you are still encountering the same error when pushing to GitHub, it’s possible that the large file is still present in the Git history.
In that case, you’ll need to rewrite the Git history to completely remove the file from the repository.
Remove the file from git history
To remove the file from Git history and resolve the issue, you can follow these steps:
- Install and set up the BFG Repo-Cleaner:
a. Download the BFG Repo-Cleaner JAR file from the following link: https://rtyley.github.io/bfg-repo-cleaner/.
b. Save the JAR file to a convenient location on your computer.
- Create a backup of your repository:
Before performing any major changes to your Git repository, it’s always a good practice to create a backup. Copy the entire repository directory to another location on your computer.
- Open a command prompt or terminal window and navigate to your git repository directory.
- Run the following command to remove the large file from the Git history:
java -jar /path/to/bfg.jar --delete-files abc.zip<br>
This command instructs BFG Repo-Cleaner to remove the file
abc.zip from the repository’s history.
After BFG Repo-Cleaner completes the cleanup process, the repository’s history will be modified. To finalize the changes, run the following command:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
This command expires old reflog entries and performs a garbage collection to remove the unwanted objects from the repository.
Now you can push the updated repository to GitHub:
git push origin <branch-name> --force
Replace <branch-name> with the appropriate branch name.
By following these steps, the large file should be completely removed from the repository’s history, allowing you to push the changes to GitHub without encountering the file size limit error. However, note that rewriting history can be a destructive operation, so make sure you have a backup of your repository before proceeding.