I had the problem of wanting to remove and ignore files that I have already commit-ed to git. Turns out, it's pretty simple:
- Add the files you want to ignore to your .gitignore file
- To unstage and remove paths only from the index, not the file system, run:
git rm -r --cached .
git add .
git commit -m "Removed sensitive files"
The files/paths listed in .gitignore should now be gone from the repository but should still exist in your file system.
Note: This will not remove files already pushed to your git repository. To remove sensitive data already pushed, see this article