Create branch - BitBucket REST API Support

I am trying to develope apapter for BitBucket Cloud using BitBucket REST API 2.0. 

My requirement is to create a new branch using API. But I am not able to find any API for that. However there is one API to GET branches but API to PUT a  branch is not there. Pls help.

2 comments

Eric Henry Atlassian Team Jul 24, 2017

Hello,

You can create a new branch using the 2.0 API as follows:

curl https://api.bitbucket.org/2.0/repositories/{repo_slug}/src/ --F "parents={parent_hash}" --F "branch={branch_name}"

You don't have to specify parents if you want the branch to be directly off the latest commit of the default branch, otherwise parents should be a hash to the commit that you want to create a branch off of.

Just an FYI: when you create a branch through the API it will create an empty commit (unless you also commit files when you create the branch).

Feel free to jump in to this HipChat room if you want some more "real-time support".

ERIC HENRY
Development Team Lead, Bitbucket Cloud

Thanks for reply. Actually I was using Bibucket local server instance not the cloud one... but I guess the API would be same except the base url..

Has the API changed?

I'm getting {"type": "error", "error": {"message": "Something went wrong", "id": "b074e82335e948b897f5525a16c883ac"}} 500 when I post to this endpoint.

 

Thanks,

Tony

Ian Dick Atlassian Team May 11, 2018

Hi Tony. Do you mind if I ask what arguments you were passing to the API? You don't have to give me the specific values for repository or for the arguments I'm just wondering which arguments you are passing to the API.

@Tony Carter This issue has been identified and fixed. We appreciate the time you took to report it. The error response is very useful!

Thanks!

This works for me.. is there a way to modify the empty commit message in the request? It currently reads "Edited with Bitbucket".

Also, you mentioned "unless you also commit files when you create the branch" .. how would you do this via api when creating the branch?

Eric Henry Atlassian Team Nov 08, 2017

@Steve Jones - Yes, you can specify a commit message and upload files at the same time.

See the API documentation for examples.

Let me know if the docs are clear enough.

Eric Henry
Development Team Lead, Bitbucket Cloud

Comment

Log in or Sign up to comment
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,320 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you