Ever accidentally add a file to git that you don’t want to delete, but also don’t want sticking around in version control? A
.env file perhaps? Every time I do this I need to look this up so I thought I would write it down here to save you and me both time. You’re welcome, self.
The trick is to use the
--cached flag along with
git rm as you might otherwise do.
For a single file
git rm --cached mylogfile.log
For an entire directory:
git rm --cached -r mydirectory