The fastest way to delete a file from GitHub

You can delete a file directly from GitHub's web interface without touching your computer. Go to the repository, find the file you want to remove, click the three dots menu in the top right of the file view, and select Delete this file. GitHub will create a new commit with the deletion, and you can add a commit message explaining why you removed it.

If you prefer to delete files from your computer first and then push the change to GitHub, you can do that too. The process is slightly different depending on whether you use the command line or a desktop app like GitHub Desktop, but both routes end with the same result: the file disappears from the repository and the deletion is recorded in your project history.

Key Takeaways

  • The web interface method (clicking delete in the file view) is the simplest option and requires no setup or command-line knowledge.
  • Deleting a file from GitHub creates a commit that records the deletion, so you can see when and why a file was removed by looking at your commit history.
  • If you delete a file locally on your computer using the command line, you must use git rm instead of just deleting it normally, or GitHub won't know the file is gone.
  • You need write access to the repository to delete files; if you don't own it, you'll need to fork it first or ask the owner for permission.

Deleting a file through GitHub's website

Open your repository on GitHub.com and navigate to the file you want to delete. Click on the file name to open it. At the top right of the file content area, you'll see a trash can icon or a three-dot menu (⋯). Click that menu and select Delete this file.

GitHub will take you to a new screen where you can write a commit message. The default message says something like "Delete [filename]", but you can change it to explain why you're removing the file. For example, "Remove old config file no longer in use" is more helpful than the default. After you write your message, click Commit changes at the bottom of the screen. The file is now deleted from your repository.

Deleting files from your computer using the command line

If you work with files on your computer and use the command line, you need to use a special command to tell GitHub that a file is gone. Simply deleting the file from your folder isn't enough—you have to use git rm so that Git knows to track the deletion.

First, open your terminal or command prompt and navigate to your repository folder. Then run git rm filename.txt (replace "filename.txt" with the actual name of the file you want to delete). This removes the file from your computer and stages the deletion in Git. Next, run git commit -m "Remove filename.txt" to create a commit that records the deletion. Finally, run git push to send the change to GitHub. The file is now deleted from both your computer and the repository.

If you accidentally deleted a file without using git rm, you can still tell Git about it. Run git add -A to stage all changes (including deletions), then commit and push as usual.

Deleting files using GitHub Desktop

If you use GitHub Desktop instead of the command line, the process is simpler. Open your repository in GitHub Desktop. In the left sidebar, you'll see a list of files that have changed. Find the file you deleted and you should see it marked as deleted (usually with a minus sign or red indicator). If you haven't deleted it yet, right-click on the file in your repository folder and delete it normally.

Once the file shows as deleted in GitHub Desktop, write a commit message in the box at the bottom left—something like "Remove old configuration file"—and click Commit to [branch name]. Then click Push origin in the top right to send the deletion to GitHub. The file is now removed from the repository.

Deleting multiple files at once

If you need to delete several files, the command line is faster than deleting them one by one through the website. Use git rm file1.txt file2.txt file3.txt to delete multiple files in a single command. You can also use wildcards: git rm *.log will delete all files ending in .log. After running the command, commit and push as usual.

Through the GitHub website, you'll need to delete files one at a time. There's no bulk delete option in the web interface, so if you have many files to remove, using the command line or GitHub Desktop is more efficient.

What happens after you delete a file

When you delete a file from GitHub, it's gone from the current version of your repository, but it's not erased from history. If you look at your commit history, you can see the commit where the file was deleted. If you ever need the file back, you can restore it by checking out an older version of the repository or by reverting the deletion commit.

Other people working on the repository will see the deletion the next time they pull changes from GitHub. If they have a local copy of the file, they'll need to run git pull to sync with the repository and remove the file from their computer as well.

Permissions and access

You can only delete files from a repository if you have write access. If you're working on someone else's repository and don't have permission, you'll see a message saying you can't delete the file. In that case, you can fork the repository (create your own copy), make changes there, and then submit a pull request asking the owner to merge your changes.

If you own the repository, you have full permission to delete any file. If you're collaborating with others, make sure you communicate before deleting important files—especially if others are still working on them.

Frequently Asked Questions

Can I undo a file deletion on GitHub?

Yes. If you deleted a file by mistake, you can restore it by reverting the deletion commit or by checking out the file from an earlier version. Use git log to find the commit where the file was deleted, then use git checkout [commit-hash]^ -- filename.txt to restore it. After that, commit and push the restored file.

What's the difference between deleting a file and removing it from Git tracking?

Deleting a file removes it from your repository entirely. Removing it from Git tracking (using git rm --cached filename.txt) keeps the file on your computer but tells Git to stop tracking changes to it. Use the second option if you want to keep a file locally but don't want it in the repository anymore.

Do I need to delete files one at a time through the GitHub website?

Yes, the web interface doesn't have a bulk delete option. If you need to delete many files, use the command line with git rm or use GitHub Desktop, which lets you stage multiple deletions at once before committing.

Will deleting a file from GitHub delete it from other people's computers?

No, not automatically. Other collaborators will still have the file on their computers until they run git pull to sync with the repository. After they pull, the file will be removed from their local copy as well.