How to download a source code file from the specific branch in Bitbucket Cloud

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

Bitbucket Cloud REST API endpoint Get file or directory contents can be used to get or download or view the contents of source code files from the specific branch in Bitbucket Cloud.

Solution

Authenticating with the Access Token:

  • To download a file named bitbucket-pipelines.yml, which is present in the master branch, the below CURL command can be used:

1 curl -H "Authorization: Bearer REPLACE-WITH-THE-ACCES-TOKEN" -o DOWNLOADFILENAME.YML "https://api.bitbucket.org/2.0/repositories/WORKSPACEID/REPONAME/src/master/bitbucket-pipelines.yml"

ℹ️ Replace with the access token, workspace ID, and repository name.

ℹ️ DOWNLOADFILENAME.YML is the file name you wish to download the content from the API and store it in the file. This part -o DOWNLOADFILENAME.YML can be removed if you don't wish to download a file and wanted to view only the contents.

Authenticating with the App Password:

1 curl -u username:apppassword -o DOWNLOADFILENAME.YML "https://api.bitbucket.org/2.0/repositories/WORKSPACEID/REPONAME/src/master/bitbucket-pipelines.yml"

ℹ️ Replace with the username, App password, and repository name.

Updated on April 24, 2025

Still need help?

The Atlassian Community is here for you.