Samples or commands for modifying bitbucket branch permissions using powershell or git commands

Samples or commands for modifying bitbucket branch permissions using powershell or git commands.

We do not have Bit bucket CLI rather, hence suggest a good approach model to execute the above scenario.

2 answers

This widget could not be displayed.

Hi Daniel! Git itself does not have branch permissions. You could create one private repository and one public repository and only push the development branch to the public on while keeping the master only in your private repository.

For branch specific permissions you need a server-side authorization layer like Gitolite for example (note that this requires you to be managing your own Git server). You can find more info at Git on the Server Gitolite.

Alternatively, you can use Bitbucket to manage branch permissions. You can learn more in the article Using branch permissions.

Hope that helps!

Ana

I've done it with bash and the free token authenticator add-on.  Here's a sample script for setting the "no changes" permission (with Group1 and Group2 exempt from it) against the current "development" branch (based on the branching model):

#!/bin/bash

export TOKEN='Fr1bRsIEPq[...]AmM='

read -r -d '' JSON <<'EOF'
{"type":"read-only", "matcher":{"id":"development", "type":{"id":"MODEL_BRANCH"}, "active":true}, "users":[], "groups":["Group1","Group2"]}
EOF

echo $JSON |
curl -s -H "X-Auth-User:gsylvie" \
-H "X-Auth-Token:$TOKEN" \
-H "Content-Type: application/json" \
--data @- -X POST \
https://vm.bit-booster.com/bitbucket/rest/branch-permissions/2.0/projects/PROJECT/repos/repo/restrictions

 

Deleting branch permissions is a bit trickier.  I had to resort to installing the jq command from github to extract the ID of the restriction to delete:

export ID=$(\
echo $JSON | \
jq '.values[] | select(.type=="read-only" and .matcher.id=="development") | .id' \
)

 

If you're trying to propagate a standard set of branch permissions out to all your repositories then I recommend using my paid add-on:  Control Freak for Bitbucket Server.

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,317 views 8 11
Read article

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