Shlag Stag Shlag Stag - 8 months ago 91
Git Question

How to remove a too large file in a commit when my branch is ahead of master by 5 commits

I've been stuck all day on this issue, looking for an answer here :( ...


I'm working alone on a project and I used github until now to save my work other than on my computer.
Unfortunately, I added a very large file to the local repository : 300mb (which exceed Github's limit).

What I did

I will try to make an history of what I made :

  1. I (dumbly) added everything to the index :

    git add *

  2. I committed changes :

    git commit -m "Blablabla"

  3. I tried to push to origin master

    git push origin master

    It took a while, so I just CTRL+C, and repeated step 2 and 3 four times, until I realised that a file was too large to be pushed to github.

  4. I made the terrible mistake to delete my large file (I don't remember if I did a git rm or a simple rm)

  5. I followed the instructions on (

  6. When I try to git filter branch, I get the following error : "Cannot rewrite branches: You have unstaged changes."

Thanks in advance !


When you deleted your file, that will be a change and that is the unstaged change that git is complaining about. If you do a git status you should see the file listed as removed/deleted. To undo this change you should git checkout -- <filename>. Then the file will be back and your branch should be clean. You can also git reset --hard this will bring your repo back to the status where you made your commit.

I am assuming that it is the last commit that has the very large file that you want to remove. You can do a git reset HEAD~ Then you can redo the commit (not adding the large file). Then you should be able to git push without a problem.

Since the file is not in the last commit then you can do the final steps without a problem. You just need to get your changes either committed or removed.