Deleting the source branch when merging a pull request

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

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

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

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.

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.

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

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

0 vote

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 I'm New Here Apr 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

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.

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

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".

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

24,011 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you