Git: remove files from repository only

This is a translated and adapted version of the original article (German).

There are situations when you want to delete files or directories in the repository only, e.g. when they are added to .gitignore.

The classic git rm would delete files from the working tree or local file system, too. The solution is the option --cached.

When you want to delete a file (e.g. file_to_delete) from the repository only you can use the command

The command for directories looks similar (except you need the -r option):

Don’t forget to commit and push.

Pro-Tip: if you want to delete all files matching the .gitignore fromt the repository you can use

Source: 1, 2, Git logo: Jason Long (CC-BY)

Gefällt dir der Artikel? Dann empfiehl ihn weiter!
LESETIPP  .tar.gz mit vim auflisten

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.