How to recover deleted branches

Is there any way to recover deleted branches, even restoing a repositiry as it was?  Not clear how it happened but many braches were dekleted by a naive user.

1 Like

Hi @jpffitch,

Welcome to the Github Community Forum!

I’m sorry to tell you, but I don’t really think so. All the commits, branches and tags are pointers to a specific memory address. As long as the pointer are alive (not deleted) you can retrive every events in history, but if these pointers are pull off from history the addresses can be use from other software. Obviously softwares overwrite the value of the addresses used.

This is for local repository, but if you have this repository in github maybe there is a possiblity. I immagine that github have clusters of databases where the repository are stored, so it can be possible to retrive an old version of a repository from a low layer database and restore it. You could try to contact support and ask.

Hope this helps, ask if you have more questions.


Mark helpfull posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great contents!

1 Like

Thanks @wabri for giving your great explanation. @jpffitch We can’t restore the branches for you, but we can send you links that you can use to restore the branches on your end.

If you can send us a link to the repository on GitHub we can check out logs and send those links over. If you haven’t already, please contact us at with the info so we can look into that further.

This is something private support will need to assist you with.


It depends. 

Remember that git is a Distributed VCS, so, the security and integrity is a natural feature of this. 

So if someone delete a branch from the remote repository (GitHub), it’s possible that anyone have a copy on their local repository. 

In the other hand, if some delete the branch from their local repository, this person could restone the deleted branch from their local repository using the reflog command.


You can use Github Events API to identify the hash of push event and recreate the branch according to this answer on Stackoverflow. 

The GitHub Events API allows to browse through the last events:


The “pushEvent” is the one to look for.

Then one can directly create a branch on GitHub in order to make that commit visible again (because not dangling anymore, but reference by an actual object like a branch):

curl -i -H “Accept: application/json” -H “Content-Type: application/json” -X POST -d ‘{“ref”:“refs/heads/D-commit”, “sha”:“384f275933d5b762cdb27175aeff1263a8a7b7f7”}’

JSON request

“ref”: “refs/heads/D-commit”,
“sha”: “384f275933d5b762cdb27175aeff1263a8a7b7f7”

 You might need to use a token for the authentication.