05 — Deleting files and directories
Nothing is ever truly lost: a deletion is just another commit, and the old content stays in the history.
Deleting one file
- Open the file.
- Press the … menu at the top right of the file view.
- Choose Delete this file (or use the 🗑️ icon next to the edit pencil).
- Write a commit message and press Commit Changes.
Deleting a folder
- Open the folder.
- Press the … menu next to Add File.
- Choose Delete this directory.
- Commit.
Everything inside the folder is removed in that single commit.
Deleting several files at once
The browser deletes one path at a time. For a large clean-up, work from your computer (chapter 10):
git rm -r old-folder
git commit -m "remove old folder"
git push
Getting a deleted file back
- Open History on the folder that used to contain it, or the repository history.
- Find the commit before the deletion.
- Open the file at that commit and copy the content, or press Browse source at this point and recreate it.
Anything that was ever committed can be recovered. Something you typed in the editor but never committed cannot.
Careful with
- Deleting the folder instead of the file — check the menu title says file when you mean one file.
- Protected branches — if
mainis protected, deletion goes through a pull request instead (chapter 09). - Secrets — deleting a password from a file does not remove it from the history. Change the password itself.