This guide describes how to restore a deleted branch using GitHub.

Note: The following instructions only apply to restoring a branch that was merged previously, and then deleted via a Pull Request on GitHub. The process for restoring branches deleted by other means is beyond the scope of this guide.

As an example, this guide uses the WayPoint Ventures’ test repository (Testrepo1) on GitHub at https://github.com/WaypointVentures/Testrepo1/. Modify the following instructions to suit your preferred Git repository (repo).

Topics in this guide

Restore a deleted branch to GitHub

Complete the following steps to restore a deleted branch using GitHub.

  1. Open a web browser, go to the URL for the project’s GitHub repo, and sign in to GitHub.

    For example, go to the WayPoint Ventures’ test repository (Testrepo1) on GitHub at https://github.com/WaypointVentures/Testrepo1/.

  2. Select the Pull requests tab from the top menu.

    'Pull requests' tab on GitHub

  3. Choose Closed from the Pull request menu to view a list of all previously closed pull requests.

    'Closed pull requests' button on gitHub

  4. From the list of closed pull requests, select the pull request that contains the deleted branch you want to restore.

    For example, choose arbitrary edit to README for branch recovery demo (near the end of the page).

    Example closed pull request on GitHub

  5. Scroll down through the messages, past the merge point, and select the Restore branch button.

    'Restore branch' button on GitHub

  6. Return to the top of the page and select the Code tab.

    'Code' tab button on GitHub

  7. Select the branches dropdown, and verify that your restored branch is on the list of available branches.

    For example, in the following image, the branch called DLtest1 is a restored branch.

    'Branches dropdown' on GitHub

  8. Add the restored branch into your local repo with the git pull command by following the guide Update branch (pull).

    Note: If you don’t have a local repo, create one by cloning the project’s GitHub repo using the guide Download course files (clone repo).

  9. After you have pulled the restored branch into your local repo, switch to the restored branch by following the guide Switch branches.

You have restored a deleted branch with GitHub successfully.

Appendices

Check the following supplementary Appendices for more details and context.