I want to create a new branch named test-branch-name
from the master
branch in a given repository. So as per the documentation provided here, I tried creating a new branch in the repository using Postman.
curl --location --request POST 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo_name>/refs/branches' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <auth_token>' \
--data-raw '{
"name" : "test-branch-name",
"target" : {
"hash" : "default"
}
}'
With above-mentioned request, I get this response.
{
"type": "error",
"error": {
"fields": {
"target.hash": "Commit not found: default"
},
"message": "Bad request"
}
}
If, instead of the default
hash, I put the full commit hash of the latest commit from the master
branch in the request payload, the API call creates the branch from develop
branch and not from master
.
What am I missing?
Hello @Akshay Maldhure,
Welcome to the Community!
A branch in Git is a pointer to a commit. Bitbucket needs to understand which commit you want to create the branch at. So the value of hash should be something identifying a commit. This can be its hash, a tag or a branch name. You get the error because your repository doesn't have any branches or tags called default, and obviously it's not a valid commit hash too.
As for master vs develop problem when using hash you mentioned, this shouldn't happen. Can you double check you used the right commit hash? The only other explanation I can think of is that master and develop point at the same commit, but I guess that's not the case.
If you're sure you used the right hash, and you still get the branch created at the wrong place, do you mind opening a support case with us and pointing there to the repo in question and dumping commands you ran with their outputs?
Cheers,
Daniil
If, by making sure about using the right hash, you mean going to https://bitbucket.org/libertywireless/<repository_name>/commits/branch/master, clicking on the latest commit and using the full commit has which appears in the browser's address bar, then yes, I'm sure I'm using the right hash. I've created a support request https://getsupport.atlassian.com/servicedesk/customer/portal/11/BBS-128678 for this issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to define the target --> hash for newly created repo
Please guide me to do the same.
Thanks&Regards
Karthikraj.M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to define the target --> hash for newly created repo
Please guide me to do the same.
Thanks&Regards
Karthikraj.M
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.