RunOfflineTools Logo RunOfflineTools
🌿 Reflog Branch Recovery

Recover Deleted Git Branch

Did you run git branch -D by mistake? Use this tool to generate the exact git reflog query and recreate your lost branch in under 60 seconds.

Select Your Emergency Scenario

What went wrong in Git?

Diagnostic Questions

Don’t know the SHA? Step 1 in the terminal commands will search it for you!

🟒 Safe Operation

Git commits are rarely deleted immediately. Git reflog preserves orphaned commits for up to 30-90 days.

Generated Terminal Command
# Step 1: Find the lost commit SHA in your Git reflog:
git reflog --date=relative | grep -i "featurepayment-v2"
# Or view the last 20 reflog actions:
git reflog -n 20
# Step 2: Recreate the deleted branch from the recovered commit SHA:
git checkout -b feature/payment-v2 4a89d12
Interactive Git Tree Transformation
Before:
[Orphaned Commit: 4a89d12] (No branch points here)
After Execution:
[feature/payment-v2] -> Points to commit 4a89d12 (Fully Restored!)
β€Ί

git reflog records every time HEAD moved in your local repository, even after running git branch -D.

β€Ί

git checkout -b attaches a new branch pointer to that exact commit, instantly restoring all your files.

πŸ’‘
Emergency Stash Rule:

Whenever you feel unsure before running any history-altering Git command, run git stash create or git branch backup-before-fix. This gives you an unbreakable fallback point.

The 2-Step Branch Recovery Protocol

  1. Step 1: Locate the Commit Hash with Reflog

    Run git reflog or filter by branch name: git reflog | grep "your-branch". Look for the last commit SHA right before the checkout or branch deletion occurred.

  2. Step 2: Reattach a New Branch Reference

    Once you identify the hash (e.g., 4a89d12), execute git checkout -b your-branch 4a89d12. All files, commits, and logs will be restored immediately.

Frequently Asked Questions

Can I recover a branch after running 'git branch -D'?

Yes! 'git branch -D' only removes the branch pointer reference. The actual commits remain safely intact in your local repository database and can be located using 'git reflog'.

How long do deleted branches remain recoverable?

Git preserves unreferenced commits in the reflog for typically 30 to 90 days before running git prune or automatic garbage collection (git gc).

What is the command to restore the branch once I have the commit SHA?

Run 'git checkout -b <branch-name> <commit-sha>'. This immediately recreates the branch pointer at that exact commit.

What if I deleted a branch on GitHub / remote?

If someone else or you locally still have the commits, you can push them back. Alternatively, GitHub retains deleted branches for a short periodβ€”you can often restore them with one click under the 'Branches' tab on GitHub.