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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.