Adding a .gitignore to an existing repo
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes everything from theindex, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
You can also remove individual files, if you don't want such a drastic approach:
git rm --cached filename