Suppose you have been working for a long time on a project, and now you want to delete some files from you project because … (the reason does not really matter at this point).
You may want to completely erase a file or a whole directory from your repository. The file or directory may be kept in the local copy or deleted as well.
If you want a complete removal use git rm:
1 2 3 4
If you want to keep your local copy use git rm —cached.
1 2 3 4
In the latter case don’t forget to add the file or directory to your .gitignore file, otherwise Git will bother you with annoying status messages.
One last thing you should keep in mind is that erasing data from a repository means only that the information is not present in the actual commit and in all future incarnations of the code. The data can be restored from the previous states of your repository. If you want to wipe your sensitive data consider reading the appropriate GitHub Help page on this topic.