'How to push a big NextJS project to GitHub

I wanna push my NextJS Project to GitHub but I always get an error that says my .next/cache folder exceeds GitHub's file size limit.

I tried to solve this by adding the next folder to the .gitignore file.

This is my .gitignore file

node_modules
next
.env

Then I followed this steps:

  1. Make changes in .gitignore file
  2. Run git rm -r --cached . command.
  3. Run git add . command
  4. git commit -m "Commit message" or just git commit or continue working.
  5. git push

But it still didn't work.

Error that I got

remote: error: File .next/cache/webpack/client-development/32.pack is 122.93 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/71.pack is 126.09 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/9.pack is 155.84 MB; this exceeds GitHub's file size limit of 100.00 MB

Did I write something wrong in my .gitignore file or is there another problem?

Thank's for helping out!



Solution 1:[1]

next and .next are different folders.

Solution 2:[2]

The only thing that worked for me was this:

git rm --cached .next/ -r

Then checking git status

git status

Check how far ahead you are

On branch master
Your branch is ahead of 'origin/master' by 8 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Then run the following appending how far ahead you are

git reset HEAD~8

Then:

git add .
git commit -m "bug fix"
git push -u origin main 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Paul Wansiedler
Solution 2