How to Recover deleted Repositories in Github

Hey there, I was writing my code for a project I’m handling without team members this time, and I mistakenly deleted the repo on GitHub. I mean, I thank my God that it is not a team repo, so how can you recover your repo that you mistakenly deleted? Follow me as I explain step by step how you can recover it

If the repository has been deleted, the error remote: Repository not found is expected. Here’s what you can do if the repository no longer exists:

  • Verify if the Repository is Deleted

    Yes. The first thing to do is to verify maybe the repository has been deleted or not using the steps below:

Are You There GIF

  • Recover the Repository

    To recover the repository, but wait, it is possible with Github

    all things are possible GIF

    With Github is not possible, but there is a way we can go about it. If the repository was deleted by accident and you are the owner, unfortunately, GitHub does not provide a way to recover deleted repositories.so the only way is to recreate another repository but with the same name as the Repository you deleted

    • Recreate the Repository

      Create a New Repository on GitHub

      • Go to your GitHub account → New Repository.

      • Use the same name as the deleted repository (the name you saved in the deleted repo) to match the old remote URL.

      • Initialize it with a README file if you'd like.

      • If you still have the project locally on your computer, you can link it to the new repository:

          git remote set-url origin https://github.com/SardiusJay/thedeletedreponame.git
        
      • Push your existing code to the new repository:

          git push -u origin main
        

Do You Understand GIF

Restore Data from Local Backup

Now that you have recreated the repository, if you have a local copy of the project, you can use it to recreate the repository:

  • Check your project folder and verify .git the directory is present (this confirms the project is a Git repository).

If you no longer have the project locally and there are no backups, the data is unfortunately lost😢😢. If you weren’t the owner and the repository was deleted by someone else, the best is to reach out to the repository owner and ask if they have a backup or can recreate the repository. And if it was deleted intentionally, confirm if they still want to share the code.

Prevent Future Loss

To avoid losing your work in the future:

  • Keep a local copy of your project with version control
  1.  git clone https://github.com/username/repository.git
    

    Regularly back up repositories to another service like GitLab, Bitbucket, or even your local machine.

I hope this was helpful. Share your feedback in the comment section.

Happy See You GIF

if you want more of this from me, connect with me on

X: My X Handle (King Sardius)

LinkedIn: Oluwatobi Abidoye

Did you find this article valuable?

Support Abidoye Oluwatobi's Blog by becoming a sponsor. Any amount is appreciated!