Git Remove

The git rm command is for "removing" files and directories, it will remove files from the git index/stage and also the local file system. You can ask git to leave the local file in place, thus just removing it from git.

Command Abbreviated Description
git rm myfile delete myfile from file system and remove from git
git rm --force myfile -f remove the file, even if it has uncommitted changes
git rm -r mydir delete the directory and all files in it
git rm --cached myfile leave the file in place by remove it from being tracked by git

I first came across this because IntelliJ has no user interface way of doing this. I needed to leave a directory on the file system but remove it from git. After adding the directory to the .gitignore file and running git rm -r --cached mydir

See also: