Remove a file from a Git repository without deleting it from the local filesystem

delete-file, git, git-rm, remote-server, repository

Solution

The `git rm` documentation states:

When `--cached` is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

So, for a single file:

git rm --cached file_to_remove.txt

and for a single directory:

git rm --cached -r directory_to_remove

Problem

I want to remove a file from my repository. ``` git rm file_to_remove.txt ``` will remove the file from the repository, but it will also remove the file from the local file system. How do I remove this file from the repo without deleting my local copy of the file?

Original source

Related problems