0

So I tried to push a directory to github from windows. I did the git init and git add . prior to making the .gitignore file. So when I pushed there was a folder that was loading which I did not want in there. I ended up getting the "remote: error: File subdir/to/ignore/... is 240 MB; this exceeds GitHub's file size...

So I now in my .gitignore I have:

subdir/
old/
__pycache__/
*.pdf
Data/

I ended up trying to redo the git procedures with:

git remote rm origin
git rm -r --cached .
git add .
git commit -m "First commit of files"
git branch -M main
git remote add origin https://...
git push -u origin main

So then the git process tried to push the same subdir/to/ignore/... So then I moved this folder to a totally different location so that it would not be in the directory. Then I did the procedures above, but the same thing happened. "remote: error: File subdir/to/ignore/... is 240 MB; this exceeds GitHub's file size...

What do I need to do?

Shane S
  • 1,747
  • 14
  • 31
  • You've added the directory to git, then added it to a .gitignore file, but that isn't retroactive. You need to [stop tracking it](https://stackoverflow.com/a/30360954/316310). – RickN Aug 18 '22 at 15:52
  • 3
    Every commit stores every file. So your first commit stores the large file (which you did not want stored). Until you get rid of that first commit, you still have that large file. The *first* commit is a little tricky to get rid of, but if you haven't made a second commit yet, you can use `git commit --amend`. If you *have* used a second commit, see existing questions of which this is basically a duplicate. – torek Aug 18 '22 at 16:14

1 Answers1

1

As others have pointed out in the comments, stuff sticks around, so this situation is actually hard to fix if you want to keep the existing repo, although it has been addressed in other questions on SO.

But... since you just created this repo, I presume you have no history you want to preserve. So start again from scratch: delete that repo altogether on GitHub. Delete the .git folder locally (which will make the directory no longer be a repo), and start all over again with your .gitignore in place this time.

After you've done your commit and before you push, you should examine what you've committed and are about to push:

  • git show --stat will list all of the files, for example.
  • du -h .git will tell you the local size of your repo, which will not be identical to the remote size, but will be a warning flag if it's really big.
joanis
  • 10,635
  • 14
  • 30
  • 40
  • This did work.! I will add that the `.git` folder is often hidden from view but it should be in the current directory. – Shane S Aug 19 '22 at 01:08