How to download repositories using the API
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
This article goes over downloading repositories using the Bitbucket Cloud API as an alternative to downloading it from the web.
Diagnosis
Downloading a repository from the web UI in zip format is straightforward. Navigate to Repository → Downloads to get a direct link that downloads the repository in a zip file. Alternatively, you can send a GET request (using curl) with the appropriate authentication to download the file directly onto your local system from the terminal. The links in Downloads tab typically formatted like this:
https://bitbucket.org/<workspace-name>/<repository-name>/get/<latest commit hash>.zip
If we use the List Download Artifacts API, it only lists the files that are manually uploaded. The Repository Link is not shown.
This poses a problem if you want to bulk download the repositories using the command line.
Solution
The endpoint below can be used to download the repository archive in .zip, .gz, and .bz2 formats.
https://bitbucket.org/<workspace-name>/<repo>/get/<branch>.<zip|gz|bz2>
Sample cURL command to download repository archive in .zip format:
curl --request GET --url 'https://bitbucket.org/sample-workspace/repo1/get/master.zip' -u <BB-username>:<app-password> --output repo1.zip
Here are some important points to remember -
- Ensure that the branch name is mentioned as shown in the format. Without the branch name, your download will not be complete
The command requires authentication. Please provide authentication with a method like app password as shown above.
- Ensure that the
--output
flag is used followed by the name of the zip file. This is necessary to create a file on the system. - Downloads are blocked when the .zip file is less than 2 GB, but the .git repository size is over 2 GB due to bug BCLOUD-23142.