GitHub has a limit on file size, and files over 100 MB cannot be directly pushed to the repository.
Solution:
- Use Git Large File Storage (Git LFS) to manage large files
- Don't upload the corresponding large file
Using Git LFS:
1. Install Git LFS
First, you need to install Git LFS. You can follow the following steps:
Windows:
Download and install Git LFS.
After the installation is complete, execute the following command in the terminal to initialize Git LFS:
git lfs install
2. Track large files
Next, tell Git LFS to track the .pth file type:
git lfs track "*.pth"
This creates a .gitattributes file to mark the file types that need to be stored using Git LFS.
3. Add and submit files
Add the .gitattributes file to Git and submit:
git add .gitattributes
git add AlexNet/best_model.pth
git commit -m "Track .pth files with Git LFS"
4. Push to remote repository
Finally, push the code to GitHub again:
git push -u origin main
Through these steps, your .pth file will be managed by Git LFS and can be successfully pushed to the GitHub repository. If the file you tried to upload has been pushed once and is rejected because the file is too large, you can execute the following command to clean up the history:
git lfs push --all origin main
This ensures that large files are uploaded to GitHub normally through Git LFS.
Do not upload the corresponding large file:
1. Remove large files from Git history
You can use the git rm command to delete the file from the current version and history:
git rm --cached AlexNet/best_model.pth
This removes the file from the Git index, but keeps a copy of the file on the local disk.
2. Submit changes
Then, you need to commit the change:
git commit -m "Remove best_model.pth from Git"
3. Push changes
Now you can push these changes to GitHub:
git push origin main
4. Ignore the file
To prevent accidental pushing the file to GitHub again in the future, you can add the file to .gitignore. This way, Git will ignore the file. Open or create a .gitignore file and add the following:
AlexNet/best_model.pth
Then submit the .gitignore file:
git add .gitignore
git commit -m "Add best_model.pth to .gitignore"
git push origin main
In this way, you will successfully remove this large file from GitHub and will not push it again in the future