Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,278
Community Members
 
Community Events
165
Community Groups

How do I check if a file exists in bitbucket remote b

Actually when the user commits a file into their local repository I need to update come information into those files automatically like for example: version string, for this I use pre-commit hooks.

To update the version string first I need to take the current version of the file from already existing file in bitbucket remote branch. Of Couse I should not take the current version for the file in my local repository since other users could have done some changes and  pushed the same file.

To get the file in bitbucket remote branch I wrote a small python script using 'requests' module. So when the file exists in remote branch it returns me the raw content of the file.  When the file does not exists it returns status code 404(page not found) . So I assumed that file does not exists! I think this is not the reliable way to say file does not exists in the branch. Is there a reliable way to check if the file exists in the remote branch or not ?

1 answer

0 votes
Vivian C Atlassian Team Aug 17, 2018

Hi Kailash,

In this case, the git command you want is:

git ls-tree -r <remote_branch>

The git command above should list all files which exists in the specified remote branch -- from there, you should be able to check if a particular file exists in the remote branch or not.

- Vivian

Hi Vivian, 

Is it possible to check the existence of a file giving the input as a URL and a branch?

Thanks

Sangeetha

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,257 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you