How to restore a deleted Azure Repo

Max Yermakhanov
ObjectSharp (a Centrilogic Company)
2 min readSep 27, 2019

I would like to start by highlighting the fact that deleting Azure Repos is limited to members of Project Administrators group, by default. In other words, a small group of users that is responsible for maintaining the balance between making sure that the rest of the users can get the most out of Azure DevOp and protecting Azure DevOps content and processes. Not a developer or a manager (or anyone else for that matter) who demands very loudly (but without any valid reasons) that they must have admin permissions. You know what I mean. So, go clean up your Azure DevOps security. Please… Anyways, enough lecturing.

If you (or someone else in your company) have accidentally deleted Azure Repo from Azure DevOps, don’t panic just yet. Recently deleted repositories go into a soft-delete state for a period of time before they are hard deleted and become unrecoverable. You can restore deleted Azure Repo using REST API within 30 days since it was deleted. You can do it using bash or command line, but I prefer to use Postman for whenever I have to deal with REST API calls.

1. First, let’s get a list of all deleted Azure Repos that are currently residing in your recycle bin by using GET request with the following URL:

https://dev.azure.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/_apis/git/deletedrepositories?api-version=5.1-preview.1

2. You will also need to create a token that you can use to authenticate to Azure DevOps from Postman. Make sure to provide proper scope and expiry date when creating the token.

3. Then, in the Postman request, click Authorization and select Basic Authentication. Enter generated token into Password field, and leave Username field blank.

4. Click Send to submit request. This will give you a list of all deleted Azure Repos. Look for the repo name you would like to restore in the JSON output and get the value of ID field for that repo.

5. Next, create new PATCH request to restore the deleted repo using the GUID discovered in the previous step.

https://dev.azure.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/_apis/git/recycleBin/repositories/{REPO_GUID}?api-version=5.1-preview.1

6. Configure Authorization tab of the request the same way we did in step #3

7. Configure Body tab of the request as raw JSON and insert the following:

{

“deleted”: false

}

8. Click Send to submit request. Check the output and make sure that “state” is set to “well-formed”.

That’s it. You should now have your repository restored. Enjoy.

--

--