Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Deleted user June 4, 2013

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?

thanks

3 answers

1 accepted

7 votes
Answer accepted
Stefan Saasen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 5, 2013

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: https://confluence.atlassian.com/display/STASH/Using+branch+permissions

Hope this helps!

Cheers,

Stefan

5 votes
arnabbanerjee September 13, 2016

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

Tim Razik August 2, 2017

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.

Julius Davies _bit-booster_com_
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.
August 2, 2017

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

Example:

http://vm.bit-booster.com/bitbucket/rest/api/1.0/projects/BB/repos/a/branches/default

Result:

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

 

Julius Davies _bit-booster_com_
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.
August 2, 2017

[deleted this duplicate of previous]

Like Steven Guitar likes this
Tim Razik August 2, 2017

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();
1 vote
Werner Meyer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 3, 2014

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.

cofarrell
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.
July 4, 2014

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:

https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTdEaXIiuLuByGqvl1Qtslqms6KQrK2QGJdKR3u87wMZkuXUbrzNg

Cheers,

Charles

Bhagwan Basnet (Aakash) January 8, 2016

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
TAGS
AUG Leaders

Atlassian Community Events