I used
curl https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/refs/branches \ -s --user {username}:{password} -g -X POST -H "Content-Type: application/json" \ -d '{ "name" : "TestBranch010", "target" : { "hash" : "default", } }'
to create a branch. But the following curl command executed via gitbash it says:
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
But the URL you guys mentioned in https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/branches is used similar as the one mentioned above. Apparently what URL would be the opt one used to create a branch using bitbucket cloud api.
Hello @shivaram,
Thanks for reaching out.
I think the quotes around the URL should fix the problem you're facing with curl.
You're right, the endpoint you referred to is meant to create a branch. For instance, this works in my repository:
curl -X POST -u dpenkin:password "https://api.bitbucket.org/2.0/repositories/dpenkin/test-repo/refs/branches" \
-H "Content-Type: application/json" \
-d '
{
"name": "new_branch_demo",
"target": {
"hash": "master"
}
}'
Note that if you need to use UUIDs instead of username or repository name, you need to put them in curly brackets (URL encoded as %7B and %7D). This is an equivalent to the previous call:
curl -X POST -u dpenkin:password "https://api.bitbucket.org/2.0/repositories/%7Bc28ad334-3dd3-48cc-b19b-ee0427cf3754%7D/%7B06dc7f1b-1102-47fe-baa9-5d1e251593ef%7D/refs/branches" \
-H "Content-Type: application/json" \
-d '
{
"name": "new_branch_demo",
"target": {
"hash": "master"
}
}'
Upd: I noticed you're using -g option for curl. In this case you can leave the curlies as-is, they'll be encoded automatically:
curl -X POST -u dpenkin:password -g "https://api.bitbucket.org/2.0/repositories/{c28ad334-3dd3-48cc-b19b-ee0427cf3754}/{06dc7f1b-1102-47fe-baa9-5d1e251593ef}/refs/branches" \
-H "Content-Type: application/json" \
-d '
{
"name": "new_branch_demo",
"target": {
"hash": "master"
}
}'
Hope this helps.
Cheers,
Daniil
Unless and until I mentioned the hash value, I could not create branch. For example
I need to mention hash: a1b2c3d4e5 in the target as the hash value is same for all branches in the repo.
how could you create a branch putting "hash":"master" ??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The target.hash parameter specifies where to create the new branch. It could be anything that identifies an existing commit in your repository: it can be a hash of that commit, a branch name (then its tip commit will be used) or a tag name (the commit it is pointing to will be used).
So the key thing here is that the commit target.hash refers to should exist. In my example repository I have a branch called master – this is why my requests work fine.
I need to mention hash: a1b2c3d4e5 in the target as the hash value is same for all branches in the repo.
I didn't really get what you mean by "hash value is same for all branches". Hash is an identifier of a commit, and all commits inside a repository have different hashes.
Hope this helps. Let me know if you have any questions.
Cheers,
Daniil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.