GitHub has over 23 million users and 1.5 million+ organizations worldwide. Needless to say, it’s one of the best platforms for developers and companies to store, track, and collaborate on software projects. Being their user makes updating the repository a part of your daily routine. Though, there are times when you need to recover the GitHub repository, whether it’s for restoring an important file or to undo all the changes.
What should I know about GitHub repo recovery?
If a repository is deleted, it will be available on disk for 90 days and may be restored via the site admin dashboard for an additional fee. For more information, see “Site admin dashboard.” After 90 days, if no legal hold is in place on a user or organization, the repository is erased and deleted permanently. If a fork network’s repository is deleted, the restored repository will be detached from the original fork network.
After a repository is removed, it may take up to an hour to restore it. Restoring a repository does not restore release attachments or team permissions. Furthermore, restored issues will not be labeled. If you want to recover a GitHub Repo that was not currently empty and is a part of the Fork network, you can contact GitHub Support.
Method 1: Recover GitHub repo for personal account
If you’re recovering a personal repository that isn’t part of a corporation, start by:
- Select “Settings” in the top-right dropdown menu.
- Choose the “Repositories” item.
- You can see a section for deleted repositories on the top bar. Choose it.
After deleting any repository, you’ll notice that another (not part of a Fork network) becomes available for recovery and appears in this list (for 90 days after deletion). GitHub warns that some repos might take an hour to show up after being deleted. If so:
- Select “Restore,” and a caution message will pop up. Confirm it to recover your repository back.
- After a few seconds, the repository will display a “Done!” message in your repository list.
Method 2: Restore a GitHub repository for an organization account
Start from the organization page if you’re looking for a repository that’s part of an organization. Then:
- Click your photo in the top right corner of GitHub home page.
- Select “Your organizations” from the drop-down menu.
- Next to the organization, select “Settings”.
- Select “Deleted Repositories” in the left sidebar.
- Select “Restore” next to the repository you want to recover.
- Acknowledge the “I Understand, restore this repository” warning message.
Method 3: Recovering GitHub repo using BackHub
BackHub is a cloud-based application that takes regular backups of all the public and private repositories on GitHub. Therefore, you can use this app to easily recover a GitHub repo.
- When you create an account for a free trial, you’ll be taken to an installation screen that syncs permissions with your GitHub account. To back up everything, use the dropdown menu to select “All repositories.”
- From there, log in to GitHub and grant BackHub permission as an application.
- Let the process take a few seconds to start.
When you first log in to BackHub, you’ll be directed to their dashboard. You’ll see a list of all the repositories you chose and the most recent backup. The application will keep your backups up to date so that you may recover them anytime.
Perform Repo Restoration via BackHub
Press the “Restore” button in the repo dropdown menu. Then:
- You’ll be prompted to enable the BackHub app again in the restore window. This installs a temporary application that you can uninstall after restoration is finished.
- Proceed to the “Restore” button in the dashboard once again after the app has been authorized. Again, you have the option to name your repository. In this case, I’ll stick with the standard <REPOSITORY_NAME>-restored format and make it private.
- BackHub will proceed to work in the background once you hit restore. The top of the dashboard informs you about the present condition. That will turn into a success message in no time.
- When you log into your GitHub account, the lost repository will be restored.
BackHub requires a new plan for each organization if your code is hosted in a GitHub organization account. These may be established right from the dashboard.