Q . Remove a file from a Git repository without deleting it from the local filesystem (working copy).

Richa ojha. asked, Jun 27 ' 2016

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?

  • git
  • git-delete

1 Answers

git rm --cached mylogfile.log

#For a directory:
git rm --cached -r mydirectory


Leave a Ansewer