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

Getting branches from a repository via bitbucket Rest API

Bernardo García March 24, 2022

Hello, community.

I am looking for the list of endpoints available for bitbucket API regarding get the branches from a repository and a specific branch.

I was expecting to see something like:

GET /2.0/repositories/{workspace}/{repo_slug}/branches/

GET /2.0/repositories/{workspace}/{repo_slug}/branches/{branch}

So I can get the commits from a specific branch. 

I know I can get commits but with this endpoint, its scope is under repository perspective. 

Do you know if there are endpoints to work with branches and recursively into its hierarchy?
I looked over the documentation but I did not see what I was looking for so that is why I am posting this question here.

In addition, I see some time ago that was not possible according to this question. Is it still true? 

1 answer

1 accepted

0 votes
Answer accepted
Bernardo García March 24, 2022

When hitting this endpoint:

https://api.bitbucket.org/2.0/repositories/<workspace>/<repository-name>`
# GET /2.0/repositories/{workspace}/{repo_slug}

You get as a result a JSON document. In the `links` attribute you got a key called `branches`. It is something like this:

 


{
"scm": "git",
"has_wiki": false,
      "links": {
      "watchers": {
            "href": "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/watchers"
      },
      "branches": {
      "href":       "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches"
},
....

So you can hit the endpoint and get the branches:


https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches
# GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches

And get a specific branch with


https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches/<branch-name>
# GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches/<branch-name>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events