Remove a file from a Git repository without deleting it from the local filesystem
Asked 07 September, 2021
Viewed 1.8K times
  • 64
Votes

My initial commit contained some log files. I've added *log to my .gitignore, and now I want to remove the log files from my repository.

git rm mylogfile.log

will remove a file from the repository, but will also remove it from the local file system.

How can I remove this file from the repo without deleting my local copy of the file?

12 Answer