Prevent branches from being deleted on PR completion


In Azure Devops I have a git repository with a develop branch. We create multiple feature branches from this branch and merge code into develop via pull requests. Once we complete the pull requests the feature branches get deleted.

I want to prevent this from happening. I’d like to keep these feature branches. How can I do that?


Prevent branches from being deleted on PR completion

Indeed, unchecking the option Delete after merging is the most straightforward solution.

However, we sometimes ignore checking this option in frequent PR. At this time, this option is not enough for us.

To resolve this issue, the workaround is set branch security for the target branch(multiple feature branches for your situation):

In Azure Devops Branches Tab -> click button for Feature branch -> Branch security -> change Force push (rewrite history, delete branches and tags) as Deny for the users and groups -> Save changes.

enter image description here

Then, the option Delete after merging will be unavailable:

enter image description here


  • Delete source branch after merging option in PR completing window is not checked/selected by default, but based on the last time’s setting. Such as if you deselect the option now, when you open the PR completing window next time, the Delete source branch after merging option will be deselected.
  • Just like Daniel said, retain feature branches is not a normal operation, we have to know some of the problems it may bring. Like, if we select the Merge type is squash commit and retain feature branches at the first PR, we will get conflict when we second PR. Because we retain the commits on the feature branch.

Hope this helps.

Answered By – Leo Liu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published