git-rm

Remove files from the working tree and index

TLDR

Remove file from tracking
$ git rm [file.txt]
Remove directory
$ git rm -r [directory/]
Remove from index only
$ git rm --cached [file.txt]
Force remove
$ git rm -f [file.txt]
Dry run
$ git rm -n [file.txt]

SYNOPSIS

git rm [options] files

DESCRIPTION

git rm removes files from the working tree and the index, staging the removal for the next commit. The `--cached` option removes files from tracking while keeping them on disk, which is useful for files that should have been in `.gitignore`.Without `--cached`, the file is deleted from both the working tree and the index.

PARAMETERS

FILES

Files to remove.
--cached
Remove from index only, keep file.
-r
Recursive removal.
-f, --force
Force removal.
-n, --dry-run
Show what would be removed.
--ignore-unmatch
Exit successfully even if no match.
--help
Display help information.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

CAVEATS

Without --cached, deletes file from disk. Removal needs to be committed. Use --cached to untrack without deleting.

HISTORY

git rm is a core Git command for removing files from version control, complementing git add.

SEE ALSO

git-add(1), git-mv(1), rm(1)

RESOURCES

Source code · Homepage · Documentation