All fixes

Help, I committed a file that should have been ignored

node_modules, build output or logs ended up in Git. Stop tracking them without deleting them from your disk.

The fix

  1. printf "\nnode_modules/\n" >> .gitignore

    Adds the folder to .gitignore, on a line of its own.

  2. git rm -r --cached node_modules

    Stops tracking it. The files stay on your disk.

  3. git add .gitignore

    Stage the new ignore rule, or it is not part of the fix.

  4. git commit -m "Stop tracking node_modules"

    Commit the removal. Heads-up: when teammates pull this, Git deletes the folder on their machines too, so they run npm install again.

node_modules/ is an example. Replace it with your own.

Why this works

.gitignore only stops Git from picking up new files. A file Git already tracks stays tracked, ignore rule or not. git rm --cached removes it from Git but not from your disk, and the ignore rule keeps it out from then on. Older commits still contain it, which is fine for build output. For secrets it is not: see the guide on committed passwords.