To delete a file from GitHub, open the file in your repository, click the three-dot menu ("...") above the file content, and select "Delete file." Write a commit message explaining why you are deleting it, then click Commit changes. The file disappears from the current branch but remains in the commit history forever, so you can always recover it later if needed.
Deleting Files on GitHub Without the Terminal
Sometimes you need to remove a file from your repository — maybe it is outdated, accidentally uploaded, or no longer part of your project. GitHub makes this straightforward through the web interface. When you delete a file on GitHub, you are creating a new commit that removes the file from the current state of the branch. However, the file is never truly gone: Git keeps every version of every file in its history, so you can always recover a deleted file by going back to a previous commit. This is an important concept to understand, especially if you accidentally uploaded something sensitive like an API key — deleting it from the latest version does not erase it from history. If you are working with AI tools like Lovable or Replit that sync with GitHub, deleting a file on GitHub will also remove it from your connected project on the next sync.
Prerequisites
- A free GitHub account (sign up at github.com)
- A repository with at least one file you want to delete
- Write access to the repository (you are the owner or a collaborator)
Step-by-step guide
Navigate to the file you want to delete
Navigate to the file you want to delete
Go to your repository on github.com. Click through the folder structure in the file list until you find the file you want to remove. Click the file name to open it. GitHub will display the file contents with a toolbar above it.
Expected result: You see the file content displayed in the browser with action icons in the toolbar.
Open the three-dot menu and select Delete file
Open the three-dot menu and select Delete file
Look at the toolbar above the file content, on the right side. You will see a few icons (pencil, copy, etc.) followed by a three-dot menu icon ("..."). Click the three-dot menu. A dropdown appears with several options. Click "Delete file." GitHub opens the commit dialog — it does not delete the file immediately.
Expected result: A commit dialog appears asking you to confirm the deletion with a commit message.
Write a commit message and confirm the deletion
Write a commit message and confirm the deletion
In the commit dialog, replace the default message ("Delete filename") with something more descriptive, like "Remove outdated config file" or "Delete unused logo image." Choose whether to commit directly to the current branch or create a new branch for a pull request. For a simple cleanup, committing directly is fine. Click the green "Commit changes" button to confirm.
Expected result: The file is removed from the repository. GitHub redirects you to the parent folder, and the file no longer appears in the listing.
Delete multiple files using github.dev (optional)
Delete multiple files using github.dev (optional)
If you need to delete several files at once, go to your repository's main page and press the period key (.) to open the github.dev editor. In the file explorer sidebar on the left, right-click on a file and select "Delete." Repeat for each file you want to remove. When you are finished, click the Source Control icon in the left sidebar (it looks like a branch), type a commit message like "Remove unused legacy files," and click the checkmark icon to commit all deletions in a single commit.
Expected result: All selected files are deleted in one commit, keeping your history clean.
Verify the file is deleted
Verify the file is deleted
Go back to the folder where the file used to live. Confirm it no longer appears in the file list. If you want extra confirmation, click the "X commits" link near the top of the repository page to see the commit history — your deletion commit should appear at the top with the message you wrote.
Expected result: The file is gone from the file listing, and the deletion commit appears in the history.
Complete working example
1# Files that should never be committed to the repo2# Add patterns here BEFORE uploading to avoid accidents34# Environment and secrets5.env6.env.local7.env.production89# API keys and credentials10*.pem11*.key12credentials.json1314# Build output15dist/16build/17.next/1819# Dependencies20node_modules/2122# OS files23.DS_Store24Thumbs.db2526# IDE files27.vscode/28.idea/Common mistakes when deleting a File from a GitHub Repository
Why it's a problem: Thinking a deleted file is completely gone from GitHub
How to avoid: Deleted files remain in the commit history. If you uploaded sensitive data like an API key, you need to rotate the key immediately — deleting the file alone is not enough.
Why it's a problem: Deleting files one by one instead of using github.dev for batch deletion
How to avoid: Press the period key (.) on your repo page to open github.dev, where you can delete multiple files and commit them all at once.
Why it's a problem: Deleting a file on the wrong branch
How to avoid: Check the branch dropdown before deleting. If you delete on main, the file is gone from production immediately.
Why it's a problem: Deleting a file that a connected AI tool (like Lovable) depends on
How to avoid: Check your connected tools before deleting. Lovable syncs with the main branch, so deleting a critical file on GitHub can break your Lovable project.
Best practices
- Always write a descriptive commit message when deleting files so your team knows why it was removed.
- Use github.dev (press .) to batch-delete multiple files in a single commit.
- Create a .gitignore file to prevent unwanted files from being uploaded in the first place.
- If you accidentally uploaded an API key, rotate the key immediately — do not just delete the file.
- Consider deleting on a branch and using a pull request so others can review before files are removed.
- Check if any connected services (Lovable, Replit, Vercel) depend on the file before deleting it.
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I accidentally uploaded a .env file with my API keys to a public GitHub repository. What steps should I take to secure my keys and remove the file safely?
Frequently asked questions
Can I recover a file after deleting it from GitHub?
Yes. Go to the repository's commit history, find the commit just before the deletion, click into it, and you can view the file as it was. Copy the content and create a new file with the same name and content to restore it.
Does deleting a file reduce the size of my repository?
Not significantly. Git keeps the file in its history, so the repo size stays nearly the same. To truly reduce size, you would need to rewrite history, which is an advanced operation not available through the web interface.
Can I delete an entire folder on GitHub?
The GitHub web interface only lets you delete files one at a time. To delete a whole folder, use the github.dev editor (press the period key) to delete each file in the folder, then commit all deletions at once.
What happens if I delete a file that my Lovable project uses?
If your Lovable project is connected to the GitHub repo via two-way sync, the file will be removed from your Lovable project on the next sync. This could cause build errors if the file was imported by other code.
Will collaborators be notified when I delete a file?
GitHub does not send a notification for individual file deletions. However, the deletion appears in the commit history and in the activity feed. If you delete via a pull request, reviewers will see the deletion in the PR diff.
Can RapidDev help me clean up my GitHub repository?
Yes. RapidDev helps non-technical founders manage their repositories, including cleaning up unused files, organizing folder structures, and setting up proper .gitignore rules to prevent future issues.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation