Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bitbucket REST API: How to fully delete a file via API?

Nalluru Srinithya
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 3, 2026

Hello Atlassian Team,

I am currently using the Bitbucket Cloud REST API to delete a file from a repository by creating a commit. The API, I am using is the /src endpoint, as documented.

API being used:

curl -X POST \
  'https://api.bitbucket.org/2.0/repositories/test_org18/bdtestrepo/src' \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -F 'branch=test' \
  -F 'message=Delete test.txt' \
  -F 'testing.txt='

This API successfully creates a commit and clears the content of the file. However, the file name still appears in the repository tree (as a zero-byte / empty file), instead of being removed entirely from the branch.

I would like to clarify the following:

  1. Is there any flag, parameter, or alternate API that allows deleting the file entirely (so that it no longer appears in the branch)?
  2. Is the /src endpoint the only supported API for file deletion with a commit in Bitbucket Cloud?
  3. Or is complete file removal only possible through the Bitbucket UI ?
  4. Is there any alternative API to delete the file?

I have reviewed the Bitbucket REST API documentation but could not find any alternative API or option to delete the file instead of erasing of content.

Any clarification on this behavior would be very helpful.

Thank you.

1 answer

0 votes
Charlie Misonne
Community Champion
February 4, 2026

Hi @Nalluru Srinithya 

May I ask why you are trying to do this with the REST API and not with a git?

To answer your question:

According to the endpoint's documentation you can delete files by using the files parameter.

The example they provide is:

curl https://api.bitbucket.org/2.0/repositories/username/slug/src \ -F files=/file/to/delete/1.txt

What you are doing with -F 'testing.txt=' is setting the file contents of testing.txt to empty, you're not deleting it.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events