Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't push to GitHub because of large file which I already deleted

Currently I have

  1. Empty GitHub repo
  2. SSH server repo (main)
  3. Local Repo

SSH server repo was the most up-to-date repo (production site) so I did a Git clone from there to local. I then tried to do a git push to GitHub.

Everything went OK but then it said something about filename.gz being too large for GitHub. I didn't need this file so I ran several Git commands to get rid of it from Git cache then pushed back to SSH server.

I don't see the large file locally but it's still on SSH server even though git diff returns nothing and git push returns "Everything is up-to-date" - And even though the file is not visible in local repo when I try to push to GitHub I still get error about it

remote: error: File fpss.tar.gz is 135.17 MB; this exceeds GitHub's file size limit of 100 MB

I followed steps under "fixing the problem" listed on GitHub help so shouldn't that have been enough?

How is the file still in the ether when it's not local or listed in git status/diff/push?

like image 550
The Atlantean Avatar asked Oct 24 '13 17:10

The Atlantean


People also ask

Can't push to GitHub because of large file?

Locally delete large files. Commit the local deletes. Soft reset back X number of commits (for me it was 3): git reset --soft HEAD~3 . Then recommit all the changes together (AKA squash) git commit -m "New message for the combined commit"

How do I remove large files from git push?

If the large file was added in the most recent commit, you can just run: git rm --cached <filename> to remove the large file, then. git commit --amend -C HEAD to edit the commit.

How do I push more than 100mb on GitHub?

To upload files larger than 100mb to github, you will need to use github large file storage system (Github LFS). WARNING: You cannot use github LFS with “forked repo”. Git will reject the commit when you try to push it to github. Git LFS has to be done on your own personal repo.


2 Answers

You can use

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD 

This will delete everything in the history of that file. The problem is that the file is present in the history.

This command changes the hashes of your commits which can be a real problem, especially on shared repositories. It should not be performed without understanding the consequences.

like image 94
MacGyver Avatar answered Oct 15 '22 03:10

MacGyver


I found squashing more useful than filter-branch. I did the following:

  1. Locally delete large files.
  2. Commit the local deletes.
  3. Soft reset back X number of commits (for me it was 3): git reset --soft HEAD~3.
  4. Then recommit all the changes together (AKA squash) git commit -m "New message for the combined commit"
  5. Push squashed commit.

Special case (from user @lituo): If above doesn't work, then you may have this case. Commit 1 included the large file and Commit 1's push failed due to large file error. Commit 2 removed the large file by git rm --cached [file_name] but Commit 2's push still failed. You can follow the same steps above but instead of using HEAD~3, use HEAD~2.

like image 33
But I'm Not A Wrapper Class Avatar answered Oct 15 '22 03:10

But I'm Not A Wrapper Class