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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

how to create master branch on empty repo by bitbucket api v2

Hi, I tried to use 

POST https://api.bitbucket.org/2.0/repositories/user/my_repo/refs/branches

{
  "name" : "master",
  "target" : {
    "hash" : "default"
  }
}

but I got 

{
"type": "error",
"error": {
"fields": {
"target.hash": "Commit not found: default"
},
"message": "Bad request"
}
}

 

I knew we need a commit, but in the new empty repo, there is no commit

1 answer

1 accepted

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 09, 2020

Hello @Huy_Tran,

Welcome to the Community!

You need to use this endpoint, specifically note branch parameter:

When a branch name is specified and the repo is empty, the new commit will become the repo's root commit and also define the repo's main branch going forward.

Hope this helps.

Cheers,
Daniil

okay thanks @Daniil Penkin , got it

I solved by this src

request({

    url: `https://api.bitbucket.org/2.0/repositories/${user_name}/${repo_name}/src`,

    method: 'post',

    headers: { 'User-Agent': 'Request-Promise', 'content-type': 'application/x-www-form-urlencoded', Authorization: `Bearer ${access_token}` },

    form: { author: 'NewsBie <support@newbee.cccc>', message: 'empty commit' }

});

Then it auto created `master` branch.

@Daniil Penkin I am trying to create a branch in an empty repository 
the solution given by @Huy_Tran  is working but I want my branch name as mainline instead master ..! 

is there a way to change?

Thanks, 
Ajay.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events