30

Possible Duplicate:
Git: Remove a file from the repository without deleting it from the local filesystem

I wish to delete files from remote repository without deleting the files from local copy. Is there a way to do this in git?

The reason is: I am working on a project at early stage. I committed some files which should not be in the repository, so I added those files into .gitignore. If I remove those files from my local copy, the program will not work.

Thanks everyone. THis question is duplicating "Remove a file from a Git repository without deleting it from the local filesystem"

Community
  • 1
  • 1

1 Answers1

55

Use this command

git rm --cached <filename>
git rm --cached -r <dir_name>
git commit -m "Removed folder from repository"
git push origin master

This removes the filename from the index, without touching your working tree.

roottraveller
  • 7,942
  • 7
  • 60
  • 65
Arafangion
  • 11,517
  • 1
  • 40
  • 72