How to delete a file from a GitHub branch

Docs say:

  • Navigate to the repository and locate the file you want to delete.
  • Click on the file to open it.
  • Click the trash can icon (:wastebasket:) labeled “Delete this file” at the top right.

There is no trash icon. It’s my repository, I have write access, can edit files and upload - but not delete!

What the hell.

git switch my_branch
git rm file
1 Like

There is much to say here, but

  1. Which docs are you talking about?
  2. There is no trash can icon in the Github UI that I can remember of recent years
  3. This is how you do it if doing it graphically (just a random repo of mine):

The real answer is of course to spend 1 hour reading Chapter 1 through 3 of the free Pro Git book. Best spent hour of my professional career. Pro Git by Scott Chacon

1 Like

There was one.

The funny thing is that duckduckgo found that image on an article titled “How to Use GitHub in 2025”.

I asked the copilot and got irritating answers.

Thanks to you all for the links. Today I found the delete command - I would bet that it was not there the last time - mebby I’m blind…

1 Like

Just for the fun of it I asked Grok:


I can definitely help with clear steps on how to delete a file from a GitHub branch! Here’s a straightforward guide:

Steps to Delete a File from a GitHub Branch

Option 1: Using the GitHub Web Interface

  1. Navigate to the Repository: Go to the GitHub repository in your browser.
  2. Switch to the Branch: Use the branch dropdown menu to select the branch containing the file you want to delete.
  3. Locate the File: Browse to the file you want to delete.
  4. Delete the File:
    • Click on the file to open it.
    • Click the trash can icon (or “Delete this file”) at the top-right of the file view.
  5. Commit the Change:
    • Enter a commit message describing the deletion (e.g., “Removed outdated file”).
    • Choose whether to commit directly to the branch or create a pull request.
    • Click “Commit changes” or “Propose file change” if creating a pull request.
  6. Verify Deletion: Ensure the file is removed from the branch by checking the file list or pull request.

Option 2: Using Git Command Line

  1. Clone the Repository (if not already cloned):
    git clone <repository-url>
    cd <repository-name>
    
  2. Switch to the Branch:
    git checkout <branch-name>
    
  3. Delete the File:
    git rm <file-path>
    
    Example: git rm docs/oldfile.txt
  4. Commit the Change:
    git commit -m "Deleted <file-path>"
    
  5. Push to GitHub:
    git push origin <branch-name>
    
  6. Verify Deletion: Check the branch on GitHub to confirm the file is gone.

Notes:

  • If the file is in a pull request, deleting it via the web interface or CLI will update the pull request automatically.
  • Ensure you have the necessary permissions to modify the branch.
  • If the branch is protected, you may need to create a pull request and get approval to merge the deletion.