Find and Restore Deleted Branches on GitHub
Restore the head branch of a closed or merged pull request with its Restore branch button. For any other deleted branch, read the tip SHA from the repository's Activity view and create the branch again at that commit.
The Fix
If the branch had a pull request, open the repository's Pull requests tab, click Closed, and open the pull request. Near the bottom of the page, click Restore branch. GitHub recreates the branch at the pull request's last head commit. You need write access to the repository.
From the command line, read the head commit from the pull request and create the ref again with the REST API:
gh api repos/{owner}/{repo}/pulls/123 --jq '.head.ref, .head.sha'
gh api repos/{owner}/{repo}/git/refs \
-f ref=refs/heads/feature/login \
-f sha=<head.sha>
The Create a reference endpoint needs the full 40-character SHA and a ref that starts with refs/. Inside a clone, gh fills in {owner} and {repo} from the current repository.
If the branch had no pull request, list recent branch deletions with the repository activity endpoint:
gh api "repos/{owner}/{repo}/activity?activity_type=branch_deletion" \
--jq '.[] | {ref, before, timestamp}'
Each entry is one deleted branch. ref is its name, and before is the commit it pointed at when it was deleted. Pass that before SHA to the git/refs call above.
Where Deleted Branches Show Up on GitHub
The branches page does not list deleted branches. You open it from the branch dropdown with View all branches, and its Yours, Active, Stale and All views cover only branches that exist now.
The record of a deletion is in the Activity view. Open it from the Activity link on the repository's main page, then pick Branch deletions in the All activity menu. Each entry shows who deleted the branch and when. Click Compare changes in the entry's menu to see its commits. The activity REST endpoint above returns the same history with the SHAs. Both are documented in GitHub's Using the activity view and List repository activities, checked December 5, 2026.
Merged pull requests are the other common source. When Automatically delete head branches is on in the repository's settings, GitHub deletes each head branch as its pull request merges. Those branches all stay restorable from their pull requests.
Why It Happens
A GitHub branch is a ref, a name that points at a commit. Deleting the branch removes the name. GitHub keeps the commits of every pull request, so a pull request still knows its head commit after the branch is gone. The Restore branch button and the git/refs call both put a new name on that commit. GitHub documents the button in Deleting and restoring branches in a pull request.
The Restore branch button appears only for the head branch of a closed or merged pull request. A branch pushed straight to GitHub with no pull request has no button, so the Activity view or a clone is the only record of its tip.
When GitHub Has No Record
If GitHub cannot give you the SHA, look in a local clone that had the branch. The commits stay in a clone's object database after the remote branch is gone. Find the tip with git reflog or a stale origin/<branch> ref, then push it:
git push origin <sha>:refs/heads/feature/login
Recover a Deleted Git Branch covers the local steps, from the delete message to git fsck.
Related
- Recover a Deleted Git Branch: local recovery with the reflog and
git fsck - Worktree or Clone to Review a Pull Request?: check out a pull request head with
pull/<n>/head - What is the Git Reflog?: how Git records where each ref pointed