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

How to get the root directory (src files) of specific branch?

meetakbari25 May 18, 2023

I have 3 branches in my repository : main, branch1 and branch2


In Bitbucket Cloud REST API Documentation, there is an API to get the root directory of main branch:


But I want to get root directory (basically all the src files under branch branch1) of branch1 not main branch. So, are there any way to achieve this by passing any query parameter on this endpoint: `GET /2.0/repositories/{workspace}/{repo_slug}/src`


I tried the solution suggested here in this question asked by someone, but even that's not working: Fetch-list-of-files-with-details-present-under-branch-or-tag/qaq-p/1148751 


If Bitbucket Developer team can confirm whether this feature (passing ?branch=<branch_name> query param to get specific branch src files) will be supported in next Bitbucket Cloud 2.0 REST API release or not, then It would be really helpful. Till then if someone know the work around or the specific solution, please comment. 


1 answer

1 vote
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 19, 2023

Hello, @meetakbari25, and welcome to the Atlassian Community!

You can use the Get file or directory contents in order to list the files in a directory of your repository : 


The {commit} portion of the URL can be replaced with a branch or tag name as well. The {path} attribute is the directory of the repository you want to list the files. If you want to list the root directory, you can leave the {path} blank, but the trailing slash at the end of the URL is required.

So a request for listing the files of the root directory of a branch named branch1 would look like below : 

curl -X GET -u USERNAME:APP_PASSWORD<workspace>/<repository>/src/branch1/

You can try using the example command above and let us know it goes :)

Thank you, @meetakbari25 !

Patrik S

Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events