You might have dealt with one of the most common problems while working with GitHub. Its none other than the “File size exceeds the GitHub’s file upload limit”. The default size of GitHub’s file upload limit is 100mb. If one tries to add any file beyond this limit, you will be greeted with an error pointing to the actual file stating this issue. In this article, I will be sharing two techniques one can use to tackle this problem before it happens to you. It’s better to use this technique before starting your work on a project as the chances of losing your data might be high.

1. Using Git-LFS(Large File System)

Firstly download and install the binary from the official git-lfs’s GitHub releases.

Releases binary list

Once installed, type the command provided below in the git directory you are working on:

    git lfs install

The result will be,

Git lfs image

Once you see this, you will be able to view out a .gitattributes file. Visit official website, to learn more about the .gitattributes file.

Now you need to add the exceeding file extension into the .gitattributes file to be tracked for large files and will be uploaded by discarding the file size limit issue.

    git lfs track "*.ipynb" # here .ipynb is the extension of the file that caused the issue for me, you can add your file extension according to your need.

If you perform a cat .gitattributes, you will be able to view that the file extension will be there in the .gitattributes file.

After ensuring that the file is there, you can perform add, commit, and push git operations.

    git add *
    git commit -m "resolved the file limit issue"
    git push origin master

The file will be uploaded considering the limit issue.

Reference: Git-lfs official website

2. Using Git log and rebase commands

Firstly, perform a git log to identify all the latest commits[if the error was from the latest commits]

    git log

This command will display all the logs from your git activity.

Once you figure out which commit was the one you want to revert to solve this large file issue, copy the commit id from the log.

Before inserting the below command, keep a backup of the repo, try to copy and paste the repo somewhere else, it will be useful later.

    git rebase -i  <commit-id>

    # for example
    git rebase -i  bd19cc2409dc3544f126d10dc6b0d10694db5d21 # here the 40 characters after the -i flag is the commit id, in your case it will be different

This will revert you to the commit you want to return to.

Once rebased, either delete the file exceeding the limit or exclude the file from committing. Once that is done, you can push all the other codes and you can use the GitHub upload feature using the GUI on the website to upload the file.