How To Recover Deleted Branch In Azure DevOps

Here is my complete, step-by-step guide on how to recover a deleted branch in Azure DevOps, covering everything from the web portal to command-line saves.

How to recover deleted branch in Azure DevOps

Method 1: The Web Portal (The Easiest Method)

Step 1: Navigate to Your Repository

Log in to your Azure DevOps organization. Navigate to your Project, then hover over Repos in the sidebar and select Branches.

Step 2: Search for the Deleted Branch

By default, the “Mine” and “All” tabs only show active branches. If you scroll through the list, you won’t see your deleted branch.

  1. Locate the “Search all branches” box in the top right corner.
  2. Type the exact name of the deleted branch.
    • Note: Partial matches often fail here. You need the full string, e.g., feature/login-update rather than just login.
  3. Once you hit enter, you will likely see “No branches found.” Look closely for a link that appears below the search bar saying: “Search for exact match in deleted branches.”

Step 3: Restore the Branch

Click that link. Azure DevOps will query the recycle bin for that specific string.

  1. Your branch should appear in the list with a Deleted status.
  2. Hover over the row to find the actions menu (the three vertical dots ...).
  3. Select the Restore branch. Check out the screenshot below for your reference.
How to recover deleted branch in Azure DevOps

The system will recreate the branch pointing to the exact same Commit ID (SHA) it was at when it was deleted.

Method 2: recovering via Git Reflog

Sometimes, you might not have access to the Azure Portal, or perhaps you deleted the branch locally and propagated that deletion to the remote. In these cases, I prefer using the command line. It makes me feel more in control of the Git history.

This method relies on git reflog, which is essentially a history of everywhere your HEAD pointer has been.

Step 1: Find the Commit ID

Open your terminal or command prompt in your repository folder. Run the following command:

Bash

git reflog

You will see a list of moves. Look for the entry where you moved away from the deleted branch or the commit message associated with the tip of that branch. You are looking for the SHA-1 hash (the alphanumeric code, e.g., a1b2c3d) next to that state.

Step 2: Recreate the Branch Locally

Once you have the SHA, you can resurrect the branch from that specific point in time.

Bash

git checkout -b <branch_name> <sha_id>
  • Replace <branch_name> with your original branch name.
  • Replace <sha_id> with the hash you found in the reflog.

Step 3: Push to Azure DevOps

Now that the branch exists locally, you simply need to push it back to the remote server to “restore” it for everyone else.

Bash

git push origin <branch_name>

Method 3: Restoring via API (For Automation)