Benni
Benni

Reputation: 664

How to push a big NextJS project to GitHub

I want to 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!

Upvotes: 7

Views: 14725

Answers (3)

cormacncheese
cormacncheese

Reputation: 1729

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 

Upvotes: 4

next and .next are different folders.

Upvotes: 1

Matthew Daly
Matthew Daly

Reputation: 9476

I strongly suspect that the problem is that the files may have been deleted, but they still exist in the history of the repository between when you last pushed and now. A file that's committed and then deleted in a later commit still exists in the repository history.

In order to resolve the issue you'll therefore need to remove them from the repository history entirely. https://docs.github.com/en/github/managing-large-files/working-with-large-files/removing-files-from-a-repositorys-history provides some guidance on doing this.

Upvotes: 3

Related Questions