210k views
4 votes
How to delete file from a GitHub repository?

1 Answer

5 votes

Final answer:

To delete a file from a GitHub repository, navigate to the file in your repository on GitHub, click the trash can icon or the 'Delete this file' option, enter a commit message, and commit the changes. It is a permanent action unless you have the file stored locally or can restore it from a previous commit.

Step-by-step explanation:

How to Delete a File from a GitHub Repository

To delete a file from a GitHub repository, you can follow these steps:

  1. Navigate to your repository on the GitHub website.
  2. Find the file you wish to delete within the repository's file list.
  3. Click on the file to open it.
  4. Above the file content, click on the trash can icon or the 'Delete this file' option.
  5. On the subsequent page, you will be prompted to enter a commit message explaining why you are deleting the file. Fill in the message.
  6. Choose whether to commit directly to the current branch or to create a new branch for this commit and start a pull request.
  7. Click the commit changes button to apply the deletion.

Note that the delete action is permanent if you don't have a local copy of the file. Moreover, it is possible to revert this action if you realize you need the file back later, but this involves more advanced Git commands or restoring the file from a previous commit. Always be sure before deleting any files from your repository.

User Overbeeke
by
7.5k points