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

Is there a way to commit and push multiple files to a bitbucket branch using rest API's.

Sneha Badera November 10, 2020

I want to commit and push multiple files of my application to a bitbucket branch using rest API's.

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 13, 2020

Hi Sneha,

Does this concern a Bitbucket Cloud repo (hosted on https://bitbucket.org/) or a Bitbucket Server one (self-hosted instance)?

The two products have different API.

In Bitbucket Cloud this is possible, you can do this using the following endpoint:

An example call would be

curl -X POST -u username:password https://api.bitbucket.org/2.0/repositories/repo-owner/repo-slug/src -F message="test commit message" -F branch=feature_branch -F folder1/my_file.txt=@/Users/tboudale/uploaded_file.txt

where
username is the username of the Bitbucket account you are authenticating with
password the password of this account or an app-password
repo-owner is the workspace ID of the workspace this repo belongs to
repo-slug is the repository slug

This command uploads the file /Users/tboudale/uploaded_file.txt from my machine, to branch feature_branch.

This file is placed in the folder named folder1 in that branch and the file in the repo is named my_file.txt (if the folder doesn't exist already, it will get created as well).

If you don't want to place the file in a certain folder, simply omit the part folder1/ and use only the name you'd like this file to have in the repo.

I'm not sure if there is an API endpoint to do the same for Bitbucket Server. Please feel free to let me know if this concerns a Bitbucket Server repo, and I'll reach out to someone from Bitbucket Server support team to assist.

Kind regards,
Theodora

Sneha Badera November 24, 2020

This is for the Bitbucket Server one (self-hosted instance), basically I have a branch checked out on my local machine and want to commit and push all the changed files to that branch on the server.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 27, 2020

Hi @Sneha Badera ,

Thank you for your reply.

This is possible via API for Bitbucket Server too with the following endpoint and PUT method:

The documentation also includes an example curl call.

Please feel free to let me know if you need anything further.

Kind regards,
Theodora

NayakS December 10, 2021

@Theodor Bogdanovic ,

Do we have any sample rest url  for this instead curl.

Like Swapna Challa likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events