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).
Prerequisites
Before you proceed complete the following:
- Install Visual Studio Code
- Install Docs Authoring Pack
- Install Word Count extension
- Install Pull Requests extension
- Install Azure Repos extension
- Install Git client
- Set Git credentials
- Terminology and concepts
- General project workflow
- Download course files (clone repo)
- Project branching policies
- Create new branch in VSC
- Send (push) files
Topics in this guide
Restore a deleted branch to GitHub
Complete the following steps to restore a deleted branch using GitHub.
-
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/.
-
Select the Pull requests tab from the top menu.
-
Choose Closed from the Pull request menu to view a list of all previously closed pull requests.
-
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).
-
Scroll down through the messages, past the merge point, and select the Restore branch button.
-
Return to the top of the page and select the Code tab.
-
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.
-
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).
-
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.