13

How can you stop a branch being accidentally deleted in a pull request?

The issue is the "Complete pull request" has got the "Delete dev after merging" check box, and this seems to be checked by default, which may be because I'm the owner of the repos.

Is there someway to disable this for all users?

SteveC
  • 15,808
  • 23
  • 102
  • 173
  • unfortunately I don't think you can out-of-the-box. You could probably author a VSTS extension that would tick this off, but that seems to be way more difficult than it needs to be. I was really hoping there would be an option when you create a pull request (Bitbucket has this ability), but alas not here. There is a similar idea here you can upvote, https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/32097544-disable-delete-branch-checkbox-in-pr-when-branch-p – raterus Feb 05 '18 at 15:59
  • :-( Well it's got my 3 votes, so hopefully the VSTS will pick it up – SteveC Feb 05 '18 at 16:02
  • Actually @SteveC, read that uservoice carefully, apparently in this user's case, he has a branch policy around the branch, and the branch doesn't get deleted. Perhaps you could set branch policies around your branches to prevent deletion to your favor, whether the checkbox is checked or not? – raterus Feb 05 '18 at 16:05
  • Yeah, I'd spotted that and I've added the "no squash" to the dev branch policy. – SteveC Feb 05 '18 at 16:39
  • Yeah, this definitely seems a bit reckless. I have Feature branches and key branches (like Dev and Master) that should not be deleted.... – Rodney Aug 27 '20 at 00:57

3 Answers3

25

For now, there is no way to disable the Delete source branch after merging option.

And there is an user voice Disable Delete Branch Checkbox in PR When Branch Policy In Place which suggest similar feature, you can vote and follow up.

The workaround is set branch security for the target branch (dev branch for your situation):

In VSTS Branches Tab -> click button for dev 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 enter image description here

BTW: 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.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
0

See this post. You just need to add a policy to the branch, then it cannot be deleted.

sirbradwick
  • 61
  • 1
  • 10
-6

I may be a bit late on this thread. I faced this problem and found solution in Azure Dev Ops. While approving you get option to deselect.

enter image description here

AmitG
  • 519
  • 6
  • 19
  • 1
    People completing the PR might forget to deselect and delete an important branch, accepted answer prevents selecting it by mistake – Henrique Brisola Jul 15 '22 at 17:13