A simpler solution to [many] GitHub large file issues

Update: In commit 15fdef2 the GitHub Docs team has added context of the provided solution to the relevant documentation.

As discussed in my proposal for updating the github docs on large files, GitHub has a hard limit of 100 MB per file for repositories. As someone who has worked on a project with large resources files, the error message remote: error: File [filename] is 200.00 MB; this exceeds GitHub's file size limit of 100.00 MB has occured to me more than once or twice. This is especially frustrating when the commit with the large file is not the most recent commit, and you have to rewrite history to remove it.

Github recommends using BFG Repo-Cleaner to remove large files from history. Altough powerful, these tools can be complex and may not be suitable for all users – especially if for many cases there is a much more straightforward solution. Or to quote myself from the linked issue:

As a clumsy git(hub) user I would have appreciated the suggestion for such a solution a lot.

Alternatively to BFG, git rebase can be used to alter the commit in an earlier state. First, you need to identify the hash of the commit where the change happened. For instance, to modify 35da8436, you may use

    $ git rebase --interactive 35da8436~

The tilde (~) is strictly necessary to reapply the subsequent commits. git rebase will now open your default git editor of structure:

    pick 35da8436 style: add new resources for roofs and clean up some old ones
    pick 09f6df0d feat/WIP!: major restructure and rewrite of components

Change pick to edit in the line of the commit to be modified. Once the file is saved, the HEAD of the repository will be at the named commit. The commit may now be modified. Repeat the steps mentioned previously:

  $ git rm --cached GIANT_FILE
  # Stage our giant file for removal, but leave it on disk
  $ git commit --amend -CHEAD
  # Amend the previous commit with your change
  # Simply making a new commit won't work, as you need
  # to remove the file from the unpushed history as well

Consequently, you may return to the original HEAD using git rebase --continue and push the smaller commits using git push.




    Enjoy Reading This Article?

    Here are some more articles you might like to read next:

  • Engaging the local community: WIMBY workshops in Styria
  • Start der BioPV-Labs: Gemeinsam die Zukunft gestalten! | BioPV
  • Extending Django Knox by secure refresh-tokens
  • Istanbul: the bridge between Europe and Asia
  • Vietnam: my first culture shock (positive)