It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there a way to make a git branch the "default"

Github has an admin setting to make a specific branch the "default" branch. We don't want people to ever check code into master, only "dev". So I'd like to make "dev" the default branch.

Does Stash have a way to do this?


3 answers

1 accepted

7 votes
Answer accepted

Yes, in the settings for a repository you can specifiy the default branch for browsing. That doesn't prevent people from commiting to master though.

For this Stash also has allows you to limit write access to certain branches by setting up branch permissions:

Hope this helps!



We can set the default branch by navigating to "Settings" > Repository Details > Default branch drop down.
However, i have a follow up question to this: Can this be achieved with a command line utility (may be: Bitbucket Command Line Interface).

Hi Arnab, have you ever figured out hos to do this via command line or Groovy Scripting?  I'm looking to get that value via groovy and or command line.

You can get the repo's default branch via the REST api (/rest/api/1.0/projects/[PROJECT]/repos/[REPO]/branches/default).



"id": "refs/heads/master",
"displayId": "master",
"type": "BRANCH",
"latestCommit": "8f5e46644b91c06449b6bafb945fe658fb77c0fa",
"latestChangeset": "8f5e46644b91c06449b6bafb945fe658fb77c0fa",
"isDefault": true


[deleted this duplicate of previous]

Like Steven Guitar likes this

Thanks that seems to work great.  If you are interested, vis ScriptRunner or a Groovy Script, I am able to get the branch information this way too.


import com.atlassian.sal.api.component.ComponentLocator;
import com.atlassian.bitbucket.repository.RepositoryService;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.repository.RefService
def repositoryService = ComponentLocator.getComponent(RepositoryService.class);
def refService = ComponentLocator.getComponent(RefService.class);

Repository rep = repositoryService.getBySlug("UP","myrepo");
int id = rep.getId();
// This returns a Branch Object refService.getDefaultBranch(rep).getDisplayId();
return refService.getDefaultBranch(rep).getDisplayId();

Im sorry could you be more specific. I click on a repository, go to settings, browse through all the tabs yet cant find a checkbox or option to make a branch the default branch for the stash project.

Hi Werner,

It should be on the first/main repository settings page/tab. You can see the branch selector here in this screenshot down the bottom right:



Inside setting you will get repository details where there is a tab called default branch.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

622 views 0 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you