gitlab

Can a deleted GitLab branch be restored?


There is a Git branch which was deleted by GitLab when closing a merge request. I would like to restore (undelete) that branch; however, I'm not seeing an option in the UI to do so.

In GitHub it is possible to restore a branch deleted by a pull request after the fact (via the "Restore branch" button on the pull request). I'm wondering if GitLab has an analogous feature for closed merge requests.

I can of course do this manually through the Git command line, checking out the last commit hash for the deleted branch, and pushing it back up to the deleted branch name. However, I would rather use the UI for something like this if it exists.

How can I restore a branch which GitLab deleted when closing a merge request?


Solution

  • Restoring a deleted branch is an open issue, so GitLab has not implemented this feature at the time of this writing.

    However, if you know the commit ID (and it hasn't been pruned), you can create a new branch from that commit:

    1. From the Web UI, go to Repository > Commits
    2. Find the commit you want and copy the SHA to your clipboard
    3. Go to Repository > Branches
    4. Click "New Branch"
    5. Enter a branch name
    6. Click the "Create from" drop-down menu and enter the commit SHA. Press enter to apply it.
    7. Click "Create Branch"

    enter image description here