How to Delete Files from GitHub: Step-by-Step Guide

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:

  1. Navigate to your GitHub repository
  2. Browse to the file you want to delete
  3. Click the file name
  4. Click the trash can icon (🗑️) or “Delete this file” button in the top-right
  5. Scroll down, add a commit message
  6. 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

TaskGitHub UIGit CLI Command
Delete a single fileUse trash icon on file pagegit rm filename
Delete a folderNot supported directlygit rm -r folder-name
Commit the changeAdd commit message in UIgit commit -m "Delete files"
Push to GitHubDone automatically if editing maingit 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.

Sharing Is Caring:

Leave a Comment