Recover a deleted VSTS git repo
VSTS provide a way to restore a deleted git branch from the web portal, but what if you accidentally deleted a repo?
There is no way from VSTS web portal to restore a deleted repo, but two nice REST APIs are out there for you to manage soft-deleted git repo.
Recently deleted repositories go into a soft-delete state for a period of time before they are hard deleted and become unrecoverable.
- Get Recycle Bin Repositories: Retrieve soft-deleted git repositories from the recycle bin.
- Restore Repository From Recycle Bin: Recover a soft-deleted Git repository.
Get Recycle Bin Repositories
I have recently deleted a repo I created “RepoToBeDeletedAndRecovered” and other 2 repos. When hitting the REST API, you will get a list of soft-deleted repos.
Restore Repository From Recycle Bin
Use the repo id to issue a PATCH request to restore the repo by changing the “deleted” field to false.
In VSTS, the repo is back!
It may be a good practices to modify the default permissions to disable “Delete Repository” permissions, you can set it at the top-level Git repositories.