Deleting the source branch when merging a pull request

Deleted user September 15, 2014

Hi,

 

Stash has the option to delete the source branch when merging a pull request.

 Is there a way to limit this? I would expect that this is configurable so that this check box will be disabled for certain branches, or that branch permissions will include 'delete' in addition to 'read' and 'write'.

We experienced a human error of accidentally deleting a branch (not feature) in this way, and we want to prevent this somehow.

 

Thanks,

Moti.

6 answers

1 vote
ThiagoBomfim
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 16, 2014

Hi Moti,

What you are asking is already implemented. From the Merging a Pull Request document:

In the 'Merge Pull Request' dialog, you can check Delete branch if you no longer need that branch in the repository. Stash checks on a few things before allowing the deletion – the branch being merged will not be deleted if:

  • The branch is the default repository branch.
  • The user does not have permission to delete the branch.
  • The branch is subject to an open pull request.

In regards to the point "The user does not have permission to delete the branch.", user in this context means the "user merging the Pull Request". Make sure you go through the Using branch permissions document. Once you set this up, you will be able to prevent unauthorised users merging the pull request from deleting the branch.

Another important point to observe here: if you are not sure that this branch should be at all deleted, why check the box during the PR creation in the first place? Stash offers ways of stopping the Pull Request from being accidentally merged. Stash implements Checks for merging for Pull Requests. Or you can write your own plugin and/or download a plugin like the Stash auto unapprove plugin.

Let me know if this was helpful.

Best regards,
Thiago Bomfim
Atlassian Support - DevTools

VijayK April 12, 2018

Hi Thiago,

 

we have similar issue , I want to understand if the Master got deleted during the merge

then what would be the reason ? How can we work RCA to investigate the issue ?

Any suggestion ?

 

Thanks,

Vijay

saurabhmsg December 16, 2020

MOti?

0 votes
Stefano Leccese February 16, 2016

Under branch permission you can add Permissions for certain branches and there you probably have your branches which also have limited access rights. When you edit your branch permission  there is also the option to flag the branch with "Prevent branch deletion".

0 votes
Deleted user September 16, 2014

Hi Thiago,

Thanks for your answer.

Unfortunately, this does not solve my use case.
Let's say we are following the gitflow branching model.

  • The release manager can merge changes from feature branches into master (and deleting the feature branches in the process).
  • Then, the release manager can merge master into a release branch - he must have write access to the release branch in order to perform the merge, but he can't accidentally delete master (the source) since it is the default branch

  • Now, the release manager want to merge the release branch into production. He has write access to both branches, and he accidentally checks the 'delete source branch' since he is used to do this with feature branches. In this case the release branch (source) will be accidentally deleted, and this is what i want to prevent.

There is no 'delete' permission - only read or write. Also, there is no way to disable the check-box via configuration for certain branches. Accidental merging is not something i'm concerned about at the moment.

I was hoping maybe there is a way to prevent this, but it seems like there isn't.

 

Thanks,

Moti.

srikanth tss December 29, 2015

Hi Moti, I am facing the exact same issue. Did you get a resolution for the problem faced? If yes, can you share?

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 15, 2014

My point is if somebody has no write access to a branch (the source branch here), then they should not be able to delete that branch via any interface. If this is not so, report it as a bug here.

Deleted user September 15, 2014

But this is not my case. I want to restrict deletion of certain branches (at least from the merge pull request dialog), even if the user has write permissions to the branch.

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 15, 2014

That sounds like a feature request, you can also make it in the same place.

Valeriy Garnitskiy September 18, 2014

We have the same problem. We'd like protect branch (release-*, feature-*) from deletion after merge it into master

0 votes
Deleted user September 15, 2014

If they are the ones doing the merge, they must have write access. I'm trying to prevent accidental deletion of source branches by the merger

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 15, 2014

I would expect that if somebody has no write access to a branch, they also cannot delete the branch.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events