How to remove a file or directory from a Git repo without removing it from your local filesystem

Another quick git tip, this time on how to remove a file or directory from a repo, but not delete the actual local file.

To remove a file, it’s pretty simple:

git rm –cached myfile

And to do a directory and all files in it:

git rm –cached -r mydirectory

Obviously after this, you should do a commit message and sync the repo with your remote host