Search code examples
gitgithubgit-lfs

Why am I unable to push large files to GitHub despite tracking with Git LFS?


I'm facing an issue while trying to push a large file (src/data/indonesia-cities.json, size: 139.64 MB) to GitHub. I understand that GitHub has a 100 MB file size limit, so I tried using Git Large File Storage (Git LFS) to handle it.

Steps Taken:

  1. Installed Git LFS.
  2. Tracked the large file with git lfs track "src/data/indonesia-cities.json"
  3. Added .gitattributes and committed the changes. Here's the sequence of commands I used:
git lfs install
git lfs track "src/data/indonesia-cities.json"
git add .gitattributes
git commit -m "Track large files with Git LFS"
git push

Despite following these steps, I'm still getting an error message when trying to push to GitHub:

remote: error: File src/data/indonesia-cities.json is 139.64 MB; this exceeds GitHub's file size limit of 100.00 MB

enter image description here

What I've Tried:

  1. Untracked the file and committed that change.
  2. Re-tracked the file with Git LFS and committed the change.
  3. Forced a push to update the remote branch. None of these steps have resolved the issue. I'm still unable to push the large file.

How can I resolve this issue and successfully push the large file to GitHub using Git LFS?


Solution

  • I managed to solve this issue by using Git LFS's migrate command. Here are the steps to resolve the problem:

    Step 1: Install Git LFS First, if you haven't already installed Git LFS, you can do so with the following command:

    git lfs install
    

    Step 2: Use git lfs migrate To move the large file into Git LFS, use the migrate command as follows:

    git lfs migrate import --include="src/data/indonesia-cities.json"
    

    This will rewrite your Git history to move the large file into LFS.

    Step 3: Add and Commit Changes Now you should stage and commit the .gitattributes file and the large file itself:

    git add .gitattributes src/data/indonesia-cities.json
    git commit -m "Migrate large file to Git LFS"
    

    Step 4: Push to Remote Repository Finally, push your changes to your remote repository:

    git push origin your-branch-name
    

    Note: Be cautious when using history rewriting commands like git lfs migrate, especially on shared repositories. Always backup your repository and inform your collaborators to re-clone after such changes.

    Source: https://docs.github.com/en/repositories/working-with-files/managing-large-files/moving-a-file-in-your-repository-to-git-large-file-storage