You can usually get a Git repository back, but the path depends on what actually went missing. If the .git folder or remote copy still exists somewhere, recovery is fast and local. If it was never pushed and the folder was deleted outright, your best hope is your editor's local history, the operating system's trash, or a backup — and after those are exhausted, the data is generally gone.

This guide works through the realistic failure cases in order of how easily they're recovered, so you can match your situation and act before anything overwrites the evidence. One rule applies throughout: stop writing to the affected disk or folder until you've made a copy.

Identify What You Actually Lost Before You Touch Anything

Recovery steps diverge sharply depending on which piece is missing, so spend two minutes classifying the problem. "My repository is gone" covers at least six distinct states, and using the wrong fix can make the situation worse.

Symptom What's probably missing Recoverable?
Folder exists, git status says "not a git repository" The .git subfolder Yes, if you can restore .git or re-clone
Folder deleted entirely, but pushed to a remote Local working copy only Yes, clone again
Commits vanished after a reset or rebase Commit objects, refs moved Usually yes, via reflog
Branch deleted A branch ref Yes, via reflog or remote tracking
Files deleted and committed File contents in history Yes, from an earlier commit
Whole project never pushed, disk wiped Everything Only from backups or file recovery

Run a quick inventory before acting. Open a terminal in the parent directory and list what's there:

If the project folder appears, change into it and run git status. A "fatal: not a git repository" message means the folder survives but .git is gone — a different problem from a missing folder, and often easier to fix because the files themselves are intact.

Get this classification right. A reader who deleted a branch and starts hunting for file-recovery software wastes time and risks overwriting nothing useful; a reader who lost an unpushed folder and starts with git reflog is running commands against a repository that no longer exists.

Get the Repository Back When the Remote Still Has It

This is the most common and easiest case: the work was pushed to GitHub, GitLab, Bitbucket, Azure DevOps, or a self-hosted server, and the local copy is damaged or gone. The remote is your authoritative source, so re-cloning restores everything that was ever pushed.

Prerequisites: network access to the remote, your credentials (SSH key or personal access token), and the repository URL. If the remote itself was deleted, skip to the section on deleted remotes.

1: Confirm the remote still exists by opening its web page in a browser. A 404 means the repository was deleted or renamed — check your account's repository list and any organization you belong to before concluding it's gone. 2: Open a terminal in the directory where you want the project to live. Avoid cloning into a folder that already contains remnants of the old copy, which causes a "destination path already exists" error. 3: Run git clone . Use the SSH form (git@host:owner/repo.git) if you have keys configured, or HTTPS if you'll authenticate with a token. 4: Change into the new folder with cd and run git log --oneline -5 to see the five most recent commits.

Success check: the files you expect are present and git status reports a clean working tree on the default branch. If the clone succeeds but files look old, you may be on a stale default branch — run git branch -a to see all remote branches and git checkout for the one you need.

Failure handling: an authentication error usually means an expired token or a missing SSH key; regenerate the credential at your host's settings page rather than guessing at passwords. If the clone fails with "repository not found" while the web page loads fine, you're likely authenticated as a different account than the one with access.

Recover Commits and Branches That Seem to Have Vanished

When the repository folder is fine but commits or branches disappeared, Git's reflog is your first stop — and it solves most of these cases without any file recovery. The reflog is a local log of every time a branch tip moved: commits, checkouts, resets, rebases, merges, and amends all leave entries.

Run this inside the repository:

You'll see lines like a1b2c3d HEAD@{3}: reset: moving to HEAD~2. Find the commit you want — the one from before the reset, rebase, or branch deletion — and inspect it with git show a1b2c3d. If the content is right, restore it.

For a lost commit on your current branch, create a branch pointing at it:

For a deleted branch, the reflog often records the commit the branch pointed to just before deletion. Look for the last entry mentioning that branch name, then recreate the branch at that commit with git branch .

Two limits matter. First, the reflog is local and per-clone — it does not exist on the remote, so this only works on the machine where the history happened. Second, reflog entries expire: Git's default is 90 days for reachable entries and 30 days for unreachable ones, configurable via gc.reflogExpire and gc.reflogExpireUnreachable. If the loss is older than those windows and garbage collection has run, the objects may already be pruned.

A worked example with the reflog: suppose you ran git reset --hard HEAD~3 an hour ago, discarding three commits. git reflog shows the pre-reset HEAD at, say, f4e5d6c. Running git reset --hard f4e5d6c restores all three commits and the working tree in one step. That's a two-command recovery for an accident that feels catastrophic in the moment.

Restore Files and History When .git Itself Is Missing

If the project folder is intact but .git is gone — sometimes caused by a careless rm -rf .git, a sync tool that skipped hidden folders, or a zip archive that dropped dotfiles — you have the working files but no history. Two paths exist.

The first is to re-clone from the remote and copy your current files over the fresh checkout. This is the right move when the remote has the latest pushed history and your local changes are the only thing at risk. Clone into a new folder, then compare and copy across any uncommitted edits before deleting the old folder.

The second applies when there's no remote or the remote is stale: initialize a new repository in place. Run git init in the folder, then git add . and git commit -m "Reconstructed from working files". This gives you a functioning repository going forward but a history that starts today — the old commits are not in it. If preserving the prior history matters, this isn't a recovery; it's a restart.

Check one thing before committing to either path: whether .git is actually gone or merely hidden. On macOS and Linux, ls -la shows dotfiles; on Windows, File Explorer hides them by default unless you enable "Hidden items" in the View tab. A surprising number of "my .git vanished" reports end with the folder being present but invisible in the file manager.

Rebuild a Repository Deleted From the Hosting Service

If the remote repository itself was deleted — from GitHub, GitLab, or another host — recovery depends on the host's own retention behavior and on any local clones that still exist. This is the case where having a second clone saved more than one developer's week.

Start with the host's documentation and settings. Some services offer a recently-deleted repository restoration window in account or organization settings; retention periods and exact menu labels vary by provider and plan, so confirm the current procedure on that provider's own help pages rather than relying on a remembered label. GitHub, for instance, documents repository restoration for deleted repositories within a limited window, but you should check the applicable policy for your account type at the time you need it.

Next, look for surviving clones. Every developer who cloned the repository has the full commit history and every branch they fetched. Ask each collaborator to run git log --all --oneline and git branch -a and report what they have. A clone that fetched all remote branches can be turned into a new remote: create an empty repository on the host, then from the best-preserved clone run git remote set-url origin followed by git push --all origin and git push --tags origin. That restores branches and tags, though it cannot restore issues, pull requests, releases, or wikis — those live on the server and go with the deleted repository unless the host's restore covers them.

One limitation to set expectations around: if the deletion happened long enough ago that the host's retention window closed and no clone survives, the repository content is not recoverable through Git or the host. Keep that boundary in mind before spending hours on it.

Recover Unpushed Work From Your Editor, OS, and Backups

When nothing was ever pushed, Git itself can't help — the objects never left your disk. Your remaining sources are local history features in your editor, the operating system's trash, and backups, roughly in order of how often they work.

Editor local history. Many code editors keep their own timeline of file changes independent of Git. In Visual Studio Code, the Timeline view in the Explorer sidebar (and the Command Palette entry "Local History: Find Entry to Restore") can surface previous versions of a file even after deletion, depending on settings. JetBrains IDEs keep Local History under the right-click menu on a file or folder. These recover file contents, not commit history, but for an unpushed project that's often enough to reconstruct the work. Exact menu labels vary by editor version, so confirm in your editor's current documentation.

Operating system trash. Deleting a folder in the file manager usually moves it to the Trash (macOS), Recycle Bin (Windows), or Trash (Linux desktop environments). Open it and restore the folder to its original location. This works only until the trash is emptied or its size limit rotates the item out.

Backups. Time Machine on macOS, File History or a third-party image backup on Windows, and any cloud sync service that versioned the folder are the strongest recovery source for never-pushed work. Restore the folder to a separate location first, then inspect it before replacing anything current.

File-recovery software. As a last resort, undelete tools can sometimes recover deleted folders from the disk. The critical prerequisite: stop writing to that drive immediately, because new data can overwrite the deleted blocks. Install and run any recovery tool from a different drive, and expect diminishing returns the longer the disk has been in use.

A simple success check across all four: open the recovered files and confirm the content matches your last known state, not an older autosave. Compare a file you edited most recently against your memory of it.

Make the Next Loss a Non-Event

The patterns above repeat because most losses share two causes: work that was never pushed, and no second copy anywhere. Both are cheap to fix.

Push early and often, even to a private repository. A commit that exists only on your laptop has exactly one copy; the moment it's pushed, it has two. If your team avoids pushing work-in-progress branches, push to a personal fork or a private scratch repository instead.

Keep the reflog in mind as a safety net for local mistakes, but don't rely on it as a backup — it's local, it expires, and a disk failure takes it with everything else.

For anything you'd hate to lose, maintain a copy that Git doesn't manage: a periodic archive, a synced folder with versioning, or an image backup of the machine. Test a restore once so you know the backup actually contains what you think it does.

And when something does go wrong, resist the urge to run recovery commands freely on the affected disk. Copy first, experiment on the copy, and keep the original untouched until you've confirmed you have what you need.

Questions That Come Up During Recovery

Does deleting a branch delete its commits? Not immediately. The commits become unreachable but remain in the object database until garbage collection prunes them, so git reflog can usually restore the branch within the reflog retention window.

Can I recover a repository I never pushed and then deleted? Only from sources outside Git: editor local history, the operating system's trash, backups, or file-recovery software. If none of those contain it, the data is gone.

Does cloning again overwrite my local changes? No — git clone writes into a new directory. Your old folder stays as it was, which is why cloning into a fresh path is safer than trying to repair in place.

How long does the reflog keep entries? By default, 90 days for reachable commits and 30 days for unreachable ones, controlled by gc.reflogExpire and gc.reflogExpireUnreachable. These are defaults, not guarantees — a git gc run can prune sooner if configured that way.