Over time, your GitHub repository may accumulate outdated, redundant, or unnecessary files. Deleting these files helps keep your project organized and clean. In this guide, you’ll learn how to delete files from GitHub, both through the GitHub web interface and the command line using Git.
✅ Method 1: Delete Files Using the GitHub Website
This is the simplest way to delete a file if you want to remove it directly from the GitHub interface.
🔹 Step-by-Step Instructions:
- Navigate to your GitHub repository
- Browse to the file you want to delete
- Click the file name
- Click the trash can icon (🗑️) or “Delete this file” button in the top-right
- Scroll down, add a commit message
- Click “Commit changes” (choose to commit directly to the main branch or open a pull request)
✅ This method works best for small changes or quick edits.
✅ Method 2: Delete Files Using Git Command Line
If you’re working locally or want to delete multiple files more efficiently, the command line is ideal.
🔹 Step 1: Open Terminal or Git Bash
Navigate to your local project directory.
cd /path/to/your/project
🔹 Step 2: Delete the File(s)
Use the rm
command to remove the file:
git rm filename.ext
To delete multiple files:
git rm file1.txt file2.js
To delete a folder and its contents:
git rm -r folder-name/
🔹 Step 3: Commit the Changes
After deleting the file(s), commit the changes:
git commit -m "Delete unused files"
🔹 Step 4: Push the Changes to GitHub
Finally, push the deletion to your GitHub repo:
git push origin main
Replace
main
with your current branch name if different.
🧠 Bonus: Undo Deletion (Before Push)
If you delete a file by mistake and haven’t committed yet, you can restore it with:
git restore filename.ext
✅ Summary
Task | GitHub UI | Git CLI Command |
---|---|---|
Delete a single file | Use trash icon on file page | git rm filename |
Delete a folder | Not supported directly | git rm -r folder-name |
Commit the change | Add commit message in UI | git commit -m "Delete files" |
Push to GitHub | Done automatically if editing main | git push origin main |
🚀 Final Thoughts
Deleting files in GitHub is a routine part of repository maintenance. Whether you prefer the web interface for quick edits or the command line for bulk actions, GitHub provides flexible options to keep your project clean and efficient.