Recover a deleted VSTS git repo

Hosam Kamel
Jul 4, 2018 · 2 min read

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.

  1. Get Recycle Bin Repositories: Retrieve soft-deleted git repositories from the recycle bin.
  2. 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.

GET https://{accountName}{project}/_apis/git/recycleBin/repositories?api-version=4.1-preview.1

Get Recycle Bin Repositories- Sample Request/Response

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.

PATCH https://{accountName}{project}/_apis/git/recycleBin/repositories/{repositoryId}?api-version=4.1-preview.1

Restore Repository From Recycle Bin- Sample Request/Response

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store