Deleting a branch in Git does not immediately destroy the commits — it just removes the label pointing to them. As long as those commits are still in Git's reflog, you can get the branch back.

If you are looking for how to delete a branch intentionally, see [how to delete a branch in Git](/git/faqs/how-to-delete-a-branch-in-git).

## Find the lost commit with reflog

```bash
git reflog
```

You will see output like this:

```
e3a1f92 HEAD@{0}: checkout: moving from feature/payments to main
e3a1f92 HEAD@{1}: commit: Fix currency rounding error
b7c204d HEAD@{2}: commit: Add Stripe webhook handler
4f9a831 HEAD@{3}: commit: Scaffold payments module
a1b2c3d HEAD@{4}: checkout: moving from main to feature/payments
```

The last commit on the deleted branch (`feature/payments`) was `e3a1f92` — the HEAD position just before you switched back to `main`.

## Recreate the branch from the commit hash

Use [`git checkout`](/git/commands/git-checkout) to create a new branch at that commit:

```bash
git checkout -b feature/payments e3a1f92
```

Or using the newer syntax:

```bash
git switch -c feature/payments e3a1f92
```

This creates a new branch starting at that exact commit, restoring your work exactly as it was. You can verify it with [`git branch`](/git/branching-and-merging) to see the recreated branch in your local list.

## Reflog has a time limit

By default, Git keeps reflog entries for **90 days** for reachable commits and **30 days** for commits that are no longer reachable from any branch or tag. After that, `git gc` can prune them.

## If the branch was on the remote

If the branch was pushed before it was deleted, check whether it still exists there:

```bash
git fetch origin
git branch -r
```

If `origin/feature/payments` still appears, recreate it locally:

```bash
git checkout -b feature/payments origin/feature/payments
```

For more on managing branches, see our guide on [branching and merging](/git/branching-and-merging).

Ready to streamline your Git workflow? [DeployHQ](https://www.deployhq.com) deploys your code automatically whenever you push to your repository.