The simplest way to delete a file from GitHub
You can delete a file directly on GitHub's website without using the command line. Open the repository, navigate to the file you want to remove, click the three-dot menu in the top right corner of the file view, and select Delete this file. GitHub will create a new commit that records the deletion, and the file disappears from your repository.
This method works for any file type and takes about 30 seconds. The file remains in your repository's history — GitHub keeps a permanent record of every change — but it no longer appears in the current version of your project. If you need to restore it later, you can recover it through the commit history.
If you have multiple files to delete or prefer working on your computer, you can also delete files using Git commands in your terminal. Both approaches accomplish the same thing: they remove the file from the current state of your repository while preserving the full history of what was there.
Key Takeaways
- The web interface method requires three clicks: open the file, click the menu button, and select delete.
- Deleted files remain visible in your repository's history and can be recovered if you change your mind.
- Using the command line requires you to run git rm, commit the change, and push to GitHub.
- GitHub automatically creates a commit message when you delete through the web interface, so you do not need to write one yourself.
Deleting a single file through GitHub's website
Start by navigating to your repository on GitHub and finding the file you want to delete. Click on the file name to open it. At the top right of the file content, you will see a trash icon or a three-dot menu — click whichever one appears.
A dropdown menu will show. Select Delete this file. GitHub will take you to a confirmation screen where you can review what is about to happen. The screen shows the file path and lets you write a custom commit message if you want to explain why you deleted it. If you leave the message blank, GitHub fills in a default message like "Delete filename.txt".
Click the green Commit changes button at the bottom. The file is now deleted from the main branch of your repository. If other people are working on this project, they will see the deletion the next time they pull the latest changes from GitHub.
Deleting files using Git commands on your computer
If you work with Git on your computer, you can delete files and push the changes to GitHub. Open your terminal or command prompt, navigate to your repository folder, and run git rm filename.txt — replace "filename.txt" with the actual name of the file you want to delete.
This command removes the file from your computer and stages the deletion, meaning Git is ready to record it. Next, run git commit -m "Delete filename.txt" to create a commit that documents the deletion. The message in quotes can say anything you want — it is just a note for yourself and your team about why the file was removed.
Finally, run git push to send the deletion to GitHub. The file now disappears from the repository on GitHub as well. If you made a mistake and want to undo the deletion before pushing, you can run git reset HEAD filename.txt to unstage it, then git checkout filename.txt to restore the file on your computer.
Deleting multiple files at once
If you need to remove several files, the command line is faster than clicking through the web interface multiple times. Run git rm file1.txt file2.txt file3.txt to delete all three files in one command. You can also use a pattern: git rm *.log removes all files ending in .log.
After deleting the files, follow the same steps as before: run git commit -m "Remove old log files" and then git push. This approach is especially useful when cleaning up a project folder or removing a whole category of files that are no longer needed.
Understanding what happens to deleted files
When you delete a file from GitHub, it vanishes from the current version of your project, but GitHub never truly erases it. Every change you make — including deletions — is recorded in the commit history. You can browse back through that history and see the file exactly as it was before deletion.
This is one of the most useful features of version control. If you delete a file by accident, or if you delete something and later realize you need it back, you can recover it. Click on the Commits tab in your repository, find the commit where the file was deleted, and click on it. Then click the three-dot menu next to the deleted file and select View this file to see it, or use Git commands to restore it to your current branch.
Removing files from Git history completely
Sometimes you need to delete a file so thoroughly that it no longer appears anywhere in your repository's history — for example, if you accidentally committed a password or a large file that should never have been there. The standard delete methods do not do this; they only hide the file from the current version.
Removing something from Git history requires a more advanced tool called git filter-branch or BFG Repo-Cleaner. These tools rewrite your entire repository history, which is a significant change. If you are working with other people, they will need to re-clone the repository afterward. Unless you have a specific reason to erase something from history — like removing a secret key — the standard delete is sufficient.
Frequently Asked Questions
Can I undo a file deletion on GitHub?
Yes. Go to your repository's commit history, find the commit that deleted the file, and click on it. You will see the deleted file listed. Click the three-dot menu next to it and select the option to view or restore it. If you want to restore it to your current branch permanently, you can use the command git revert [commit-hash] where the hash is the ID of the deletion commit.
What is the difference between deleting through the website and using Git commands?
The end result is identical — the file is removed from your repository. The web interface is faster for one or two files and requires no terminal knowledge. Git commands are faster when deleting many files at once and give you more control over the commit message. Choose whichever fits your workflow.
If I delete a file, will other people lose their copy?
No. Other people keep their local copy of the file on their computer until they pull the latest changes from GitHub. Once they run git pull, the file will be deleted from their local repository as well, but they can always recover it from the history if needed.
Can I delete a folder instead of a single file?
Yes. On the web interface, navigate into the folder and delete the files inside it one at a time. Using Git, run git rm -r foldername to delete the entire folder and everything in it. The -r flag tells Git to remove recursively, meaning it deletes the folder and all its contents.