If you've stumbled upon this post, there's a high chance that you are dealing with a nasty GitHub bug that can happen when you try to push a commit that includes some large files.
When this happens, the git client you use to perform the push will give you error messages similar to these ones:
remote: error: File <File Path> is 120.11 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to <Project Name>
git did not exit cleanly (exit code 1)
These files are rejected by GitHub because that service has an hard-cap of 100 MB per single file, leaving us with two options:
- Remove the offending files
- Untrack and/or exclude those files from git (as explained in the official github docs).
Unfortunately, when the above error strikes it means that we've already committed those files in our local repository, meaning that we can't simply "ignore" them anymore: we need to find a way to delete those files from our local repository. More precisely, we need to "roll back" to the moment before the commit, without losing the updated files: if we manage to do that, we'll be able to manually delete (or exclude) the offending files without losing our work.
Here's a simple guide explaining how to do that.
- Open a command prompt and navigate to the project's root folder (the folder hosting the .git hidden directory)
- Execute the following command on the master branch:
- git status
- Take note of how many commits you are ahead of the origin/master branch by looking at the command output. For example, if the command says that "Your branch is ahead of 'origin/master' by 2 commits", the number to remember is 2, which you'll have to put instead of the <num> placeholder we'll be using in the following command.
- Execute the following command to move the current HEAD of your local repository back to the commit specified, i.e. to the moment before the commit of these large files (don't worry, you won't lose any of your updated files):
- git reset HEAD~<num>
- After doing that, execute the status command again:
- git status
- The command output should now say that Your branch is up to date with 'origin/master'.
That's it! Now you can finally delete the large files (unless you haven't already done so); after that, you'll be able to re-commit everything without losing your work. Credits for this solution goes to Shreya (see this StackOverflow thread).
That's it, at leastr for now: we hope that such method will help other web designers and software developers that are struggling with this nasty GitHub issue.