sns
sns

Reputation: 191

How to recover deleted repository in Azure DevOps?

I deleted Azure Repo by mistake, now I want to restore that repo is there any way we can restore it?

If possible, please advise.

Upvotes: 10

Views: 12392

Answers (1)

Maytham Fahmi
Maytham Fahmi

Reputation: 33437

If you have deleted your repository, it will stay in Azure DevOps recycle bin for 30 days; so restoration is possible but you need to follow some manual steps as shown below.

Within 30 days, you can follow the steps below to recover your repository:

  1. Create a PAT (Personal Access Token) in Azure DevOps.

  2. You will need to use a tool such as a Postman software to make some API requests; using that, create a get request using this URL: https://dev.azure.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/_apis/git/deletedrepositories?api-version=5.1-preview.1

  3. Make Basic Auth, put the Token as a password, and leave the username empty.

  4. The response contains the id of your deleted repo (a GUID id).

enter image description here So making the request step 2, you get a JSON payload containing the REPO GUID as highlighted in yellow. That you need to copy for step 5.

  1. Make another Patch request to following URL: https://dev.azure.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/_apis/git/recycleBin/repositories/{REPO_GUID}?api-version=5.1-preview.1

With the following JSON payload body:

{
    "deleted":false
}

When you make this request, it will recover the deleted repository from recycle bin.

Note: Replace {ORGANIZATION_NAME}, {PROJECT_NAME} and {REPO_GUID} with the right values.

I have tested this way and it works.

Disclaimer: This answer knowledge is based on an article I wrote in my personal blog. It is also possible to use this tool (AzdoTools) to recover the repositories. more info about it is in the given article link.

Upvotes: 23

Related Questions