git rm <pathname>

Remove a file from the working directory and staging area.

This command is useful for deleting files from both your working directory and the staging area in a Git repository, ensuring the file is removed from version control in the next commit.

It operates by deleting the specified file from your local filesystem and staging the removal so that the change is included in your next commit.

You can use variations like git rm -f <pathname> to force removal of files that have been modified, or git rm --cached <pathname> to remove the file only from the staging area while keeping it in your working directory. Adding the -r flag allows you to remove directories recursively.

Related commands include git reset <pathname> to unstage a file without deleting it, and rm <pathname> (without git) to delete a file from your filesystem without affecting the Git index.

Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...