How can I recover a deleted remote branch?

I am using the Fork git client, I pressed the wrong button and deleted a remote branch. I never pulled this branch so I don’t have a local copy.

There is no trace of the branch on GitLab. I tried the reflog command, and there is nothing there about deleting a branch.

It’s as if this branch never existed.

Any ideas?

Hmm I am also a bit puzzled, @vice . I am asking a GitLab expert right now so hopefully I will be able to get back to you soon with an official solution.

In the meantime, I wonder if you were able to try something like git-lost-found (link to git documentation here) in order to recover it? I would have done the same as you and first tried reflog, but it sounds like that didn’t work?

Let me know what else you have tried, and hopefully by the time we re-connect, we will have made some headway on our side. Thanks! and welcome to our forum! :blush:

1 Like

Hi @vice and @Linds
Usually, removing a git branch means removing the link between the branch name and the last commit of this branch. The code is not removed, only the easy link the find it.

Every commit have a SHA1 related (something like c675144fbd35c007f910f7ffa34c251d7dd74073) that can be used to find it.
If you know the SHA of the last commit of the branch, you can just do

git checkout -b <branch> <sha>

to create a new local branch like the remote branch removed

The point is how to find the SHA of the commit.
Usually, git reflog helps because it record when the tips of branches and other references were updated in the local repository. But, unfortunately, your branch have never been in the local repository …

I’ve never used Fork git client, but you may find the SHA in the history of the branch

1 Like