Pro Tip: Removing a File from Git without Deleting it
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
Read Next
Unless you are working in a fully automated build environment like a CI runner, you will need to have some version of Composer running within your PHP codebase to be able to pull packages and configure autoloading. Composer has the …
I have always liked the idea of having a personal blog. Something that helps others tackle the tricky technical problems that I have to solve for day to day as a developer. But, in practice, a blog is a lot …