Backup247
← Back to blog

Best practices

Recovering deleted GitHub files: what actually works (and what doesn't)

· 8 min read

Backup247

Deleting the wrong file in a GitHub repo happens to everyone eventually. A merge gone sideways, a rogue git push --force, a "cleanup" PR that removed too much, or an AI agent that decided a whole folder was unused. The good news: if the file ever lived in Git, it is almost always recoverable. The bad news: Git only helps for files it actually tracked, and only inside your local reflog window.

This is the exact order we walk Backup247 users through when they open a ticket about lost GitHub files.

1. Was the file ever committed?

Start here. If the file was staged and committed at least once, you're in a strong position — Git keeps every object it has ever seen until garbage collection runs. If the file was only in your working directory (never git added) and you deleted it locally, Git cannot help you. Check your editor's local history, your OS trash, or a file-system snapshot (Time Machine, OneDrive version history, Dropbox rewind).

2. Recover a file deleted in a specific commit

If you know the commit that removed it, this is a one-liner:

git log --diff-filter=D --summary -- path/to/file
git checkout <commit-before-deletion>^ -- path/to/file

The first command finds the commit that deleted the file. The second restores the file from the commit just before it, into your working tree. Commit it and push — done.

3. Recover after a force-push wiped your branch

A git push --force or --force-with-lease doesn't actually delete commits on GitHub immediately. They live in the reflog on any machine that had the branch checked out, and in GitHub's internal reflog for roughly 90 days.

Locally:

git reflog show <branch>
git checkout -b recovery <sha-from-reflog>

On GitHub, if no one has a local copy, contact GitHub Support with the repo URL and the approximate time of the force-push. They can restore from their internal reflog while the objects are still reachable.

4. Restore from a Pull Request that was closed or deleted

GitHub keeps the commit refs of every PR under refs/pull/<n>/head even after the PR is closed and the branch deleted. You can fetch them directly:

git fetch origin pull/1234/head:pr-1234
git checkout pr-1234

This works for merged, closed, and even deleted-branch PRs, as long as the repo itself still exists.

5. The whole repository was deleted

If someone (or an automation) deleted the repo itself, GitHub retains it for 90 days. The repo owner or an org admin can restore it from Settings → Repositories → Deleted repositories within that window. After 90 days, GitHub cannot help. This is the scenario where a real, external backup matters most.

6. What Git and GitHub genuinely cannot recover

  • Files that were never committed. Uncommitted working-directory changes are invisible to Git.
  • LFS objects garbage-collected after a force-push. Git LFS runs its own pruning schedule; large binaries can vanish permanently.
  • Repos deleted more than 90 days ago. GitHub's retention window is hard.
  • Content in wikis, issues, discussions, releases, and Actions artifacts after a repo deletion. These are not part of Git objects and are lost with the repo.
  • Secrets and environment variables. GitHub does not retain deleted secret values, by design.

How Backup247 fills those gaps

Backup247's GitHub connector treats a repository the way we treat an Airtable base: a live source of truth that needs an independent, off-platform copy. Every backup captures:

  • The full commit graph of every branch (not just the default branch), including tags and refs
  • All refs/pull/*/head references, so closed and deleted PRs stay recoverable
  • Git LFS objects, resolved and stored alongside the commit snapshot
  • Repository metadata: description, topics, default branch, protection rules
  • Issues, PR discussions, releases, and wiki content, exported as structured JSON

Snapshots run hourly on Silver and Gold plans. A restore drops the repo (or any subset of files, or a single PR branch) into a new repository in your org, so your live repo is never overwritten. If a force-push wiped a branch three weeks ago, or an integration deleted a whole repo last month, restore is a few clicks — no ticket to GitHub Support, no reflog spelunking on a laptop no one has anymore.

A simple rule

If a file was committed to Git in the last week and pushed to GitHub, you can almost certainly get it back with the commands above. Anything older, anything force-pushed, anything lost with a deleted repo, and anything outside Git objects (issues, releases, LFS, wiki) needs an external backup. That is exactly the gap Backup247 was built to close.

Frequently asked questions

Can I recover a file I deleted from GitHub if it was never committed?

No. Git only tracks files after git add and git commit. If the file was only in your working directory when you deleted it, check your editor's local history, your operating system trash, or a filesystem snapshot service like Time Machine, OneDrive version history, or Dropbox rewind.

How long does GitHub keep a deleted repository?

GitHub retains deleted repositories for 90 days. The repo owner or an organisation admin can restore it from Settings, Repositories, Deleted repositories within that window. After 90 days the repository and all its wikis, issues, releases, and Actions artifacts are permanently gone unless you have an external backup.

Can I recover commits after a git push --force?

Usually yes, if you act quickly. The overwritten commits stay in the local reflog of any machine that had the branch checked out (git reflog show branch-name) and in GitHub's internal reflog for roughly 90 days. Restore locally with git checkout -b recovery <sha>, or contact GitHub Support with the repo URL and approximate time of the force-push.

How do I get back a Pull Request branch that was already deleted?

GitHub keeps every PR commit under refs/pull/<number>/head even after the PR is closed and the source branch deleted. Run git fetch origin pull/1234/head:pr-1234 and then git checkout pr-1234 to restore the exact state of the PR.

Does Backup247 back up GitHub issues, wikis and releases, not just code?

Yes. The Backup247 GitHub connector captures the full Git object graph (all branches, tags, PR refs and LFS objects) plus repository metadata, issues, PR discussions, releases, and wiki content exported as structured JSON. If a repository is deleted, everything is restorable into a new repo in your organisation.

How often does Backup247 snapshot a GitHub repository?

Hourly on Silver and Gold plans, and daily on Bronze. Restores are non-destructive: your live repository is never overwritten, the recovered content lands in a new repository so you can review and merge on your own terms.

Still have questions?

Our team is here to help. Reach out and we'll get back to you within 24 hours.