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
printf "\nnode_modules/\n" >> .gitignoreAdds the folder to
.gitignore, on a line of its own.git rm -r --cached node_modulesStops tracking it. The files stay on your disk.
git add .gitignoreStage the new ignore rule, or it is not part of the fix.
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 installagain.
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.