Branch management

Repository owners and administrators can set Branch management rules on a repository.  Through these rules, you can enforce a project or team workflow.  For example, owners or administrators can:

Understand the differences with Mercurial branch management

Unlike Git's single branch concept, Mercurial supports both bookmarks or named branches.  For Mercurial repositories, support for branch management is slightly different. Bitbucket Cloud allows you to limit pushes for both bookmarks and named branches.  You can only prevent the deletion of bookmarks; you cannot prevent deletion of named branches.

You cannot prevent history re-writes or rebasing in a Mercurial repository.

Using a repository's branch management settings

Each repository has Branch Management settings.  To view these settings for a repository, log in under account with owner or administrative rights on the repository. Then, do the following:

  1. Select the repository settings button.
  2. Choose Branch management from the left-hand navigation.

Within this dialog, you can use the * (asterisk) to match multiple branches.   Wildcards let you set up rules that apply across sets of branches.  For example, a specification PROJ-* matches PROJ-32, PROJ-66, and so on. 

Limit push powers 

You can set rules that limit who can push to a branch. Rules specify the groups and/or users that can push to a branch.  Any user that doesn't meet the rule can't push to a repository.  You can only create rules for users and groups that have write permissions or higher.  Bitbucket knows which users and groups this applies to; the dialog only shows you users and groups with this permission.

To prevent any user from pushing to a branch, you can, do this:

  1. Create a group called EmptyGroup on your account.
    You can name the group anything you like. We recommend you choose a name that reflects how the group is used. 
  2. Give the group write permissions.
  3. Go to the Branch Management page.
  4. Locate the Limit pushes to specific users and groups section.
  5. Limit pushes to a branch to the EmptyGroup group.

Users are free to interact with a branch in their local clone. When they attempt to push to the Bitbucket remote, users who aren't allowed to push to the branch receive a message that the remote rejected the push.

Git message
$ git push origin working
Password for '': 
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 326 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: permission denied to update branch working
 ! [remote rejected] working -> working (pre-receive hook declined)
error: failed to push some refs to ''
Mercurial message
$ hg push
pushing to ssh://
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
remote: permission denied to update branch elephant
remote: transaction abort!
remote: rollback completed
remote: abort: pretxnchangegroup.bb_perm hook failed

Prevent branch (bookmark) deletion

You can also prevent users from deleting branches (Git) or bookmarks (Mercurial).  To do this, you simply list the branches (or bookmarks for Mercurial users) you want to keep. 
 You can use wildcards to match multiple branches (Git) or bookmarks (Mercurial).  

Prevent history re-writes (Git only)

If the repository is a Git repository, you can prevent history re-writes (also known as a rebase).  To do this, you simply list the branches you want to keep. 

You can use wildcards to match multiple branches.

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport