Git: Delete file after ignoring it

Delete a file tracked by git after adding it to the .gitignore file

When you update the .gitignore file to start ignoring a new file, that file will not be removed on the next commit and will instead continue to be tracked. The process to actually remove a newly ignored file is a bit un-intuitive.

git rm --cached <file>

Replace <file> with the path to the file to be removed

Or, for a folder:

git rm -r --cached <folder>

Replace <folder> with the path to the folder to be removed

This will tell git to remove these files from its internal cach and their removal can be included in the next commit.

Related