11 Deleting Files in Git

Files and directories sometimes outlive their usefulness. You can remove them from your working tree and tell Git to quit tracking them using the git rm command.

This doesn’t remove the file from your repository’s history; it removes it only from your working tree going forward. You can always go back in the history of the repository and see the files or directories that have been removed.

You call git rm and provide it with a filename to tell Git to remove it (or a standard shell pattern—*.php matches all files that end in .php). You don’t have to provide the --, but it’s necessary if you’re trying to remove a file that conflicts with a command-line option. It tells Git that you’re done providing ...

Get Pragmatic Guide to Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.