node_modules keep being pushed with git despite it being ignored and removed


I’m trying to push my local git project into github remote repo. I added node_modules into one commit I made but this exceeds GitHub’s file size limit of 100.00 MB when I try

git push -u origin main


remote: error: Trace: d8e81b49d1b7e109e7b4585cf6b84d574b3888e15cb1b4f858c87c5a0147bc57
remote: error: File node_modules/node-sass/build/Release/libsass.lib is 160.60 MB; this exceeds GitHub's file size limit of 100.00 MB

Then I added .gitignore but that doesn’t work because the commit was already made

I tried to remove that node_modules from being tracked and commited using

git rm -r cached node_modules

but it keeps trying to push that when I do git push.

I don’t know how to remove node_modules from being pushed


As per the discussion under Tirth‘s answer:

You can create a new branch and manually add the commits that do not add the node_modules.


  • you are on branch master
  • the commit that added the node_modules has the hash a1a1a1a1.
  • your working tree is clean i.e. everything is committed locally

  1. Checkout the commit before the error and create the new branch (called fixed).
    If a1a1a1a1 is the first commit on master, you’ll have to create an orphan branch as per this post instead.
git checkout a1a1a1a1^
git switch -c fixed
  1. If the commit contained other things than the node modules, recreate that commit without the node_modules part.

  2. Add all the commits after a1a1a1a1 to the new branch

git cherry-pick a1a1a1a1..master

Once you are sure everything is there, you can delete the master, rename fixed to master and then (force) push the new master branch.

Answered By – Torge Rosendahl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published