---
title: "How do I recover a deleted branch or lost commit with git reflog?"
description: "Deleted a branch or lost commits after a reset or rebase? Learn how git reflog records where HEAD has been and how to bring that work back by pointing a new branch at it."
url: https://www.danny.engineering/answer/git/how-do-i-recover-a-deleted-branch-or-lost-commit-with-git-reflog
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["Git"]
---

# How do I recover a deleted branch or lost commit with git reflog?

## The short answer


Run `git reflog`, find the commit you lost, and create a branch that points at it. As long as the work was committed in your local repository, it is almost always still there.


```bash
git reflog
# find the hash, for example a81b4de
git branch feature/login a81b4de
```


## Why it happens


Deleting a branch, resetting or rebasing does not delete commits straight away. It only moves or removes the labels that point at them. A commit with no branch or tag pointing at it is called unreachable: it no longer shows in `git log`, but it stays in the repository until garbage collection removes it.


The reflog (reference log) is Git's private diary of where `HEAD` and each branch have pointed. Every commit, checkout, reset, merge, rebase and amend adds an entry. So even when no branch points at a commit any more, the reflog usually remembers it.


A few things to know:

- The reflog is local. It is never pushed, and a fresh clone starts with an empty one.
- Entries expire. By default Git keeps reachable entries for 90 days and unreachable ones for 30 days (`gc.reflogExpire` and `gc.reflogExpireUnreachable`), after which garbage collection can remove the commits.
- It only knows about commits. Uncommitted changes in your working folder are not recorded.

## How to fix it


### Recover a deleted branch


When you delete a branch, Git prints the commit it pointed at. Check your terminal first:


```bash
git branch -D feature/login
# Deleted branch feature/login (was a81b4de).

git branch feature/login a81b4de
```


If that output is gone, look in the `HEAD` reflog for the last time you were on the branch. A branch's own reflog is deleted with the branch, but the `HEAD` reflog keeps the history of what you checked out and committed.


```bash
git reflog
# 3f2a1c9 (HEAD -> main) HEAD@{0}: checkout: moving from feature/login to main
# a81b4de HEAD@{1}: commit: Add login form validation
# 7c0e5b2 HEAD@{2}: commit: Add login form

git switch -c feature/login a81b4de
```


The line just before "moving from feature/login" is the last commit you made on that branch.


### Undo a bad reset


If `git reset --hard` moved your branch too far back, the reflog shows where it was before.


```bash
git reflog
# 7c0e5b2 HEAD@{0}: reset: moving to HEAD~2
# a81b4de HEAD@{1}: commit: Add login form validation

git reset --hard a81b4de
```


If you have uncommitted changes you care about, commit or stash them before running another hard reset.


### Undo a rebase or merge that went wrong


Rebase, merge and reset save the previous position in `ORIG_HEAD`, which is the quickest way back straight after the operation:


```bash
git reset --hard ORIG_HEAD
```


If you have done other things since, find the entry from before the rebase started in `git reflog show feature/login` instead, and reset to that hash.


### Look before you restore


Not sure which entry is the right one? Inspect it without changing anything.


```bash
git show a81b4de --stat
git log --oneline a81b4de -n 5
```


Creating a new branch at a hash is always safe, so when in doubt do that and compare.


### When the reflog does not have it


For commits that were never on `HEAD`, or a dropped stash, ask Git to list objects that nothing points at:


```bash
git fsck --lost-found
# dangling commit 9d1e4f0...
```


Files you staged with `git add` but never committed may appear as dangling blobs, which you can read with `git show` and the blob hash.


## Common pitfalls

- Running `git gc --prune=now` or similar clean-up commands while trying to recover. They can delete the very commits you are looking for.
- Expecting to recover work from a remote branch someone else deleted. Your reflog only covers your own repository; ask the person who pushed it, or check whether your Git host offers a restore option.
- Waiting too long. After the expiry period, garbage collection may remove unreachable commits for good.
- Recovering with `git checkout` and a hash, then committing. That puts you in detached HEAD state; create a branch with `git switch -c` so the work has a name.

## Related reading

- [git-reflog documentation](https://git-scm.com/docs/git-reflog)
- [git-fsck documentation](https://git-scm.com/docs/git-fsck)
