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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How to find the branch name of a commit by using API?

The ultimate task I need to perform is to extract the the commits that are made to a specific branch between two time points. This is quite easy to achieve with git CLI but I am limited to Bitbucket API v1.

Of course it's not a problem to get all commits:


But then I have no branch context.

The only query that I can made successfully is to retrieve the latest commit of the branch:



Basically what I am missing is the ability to make a connection between a branch and a commit.

Any help will be appreciated. 


2 answers

Please try this. It gives the branch of a commit. 



this api response only return the latest branch.

how can I get all the branches which contain this commit?

1 vote
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 08, 2019

Hello Taras and welcome to the Community!

I research a bit on your question about linking commits to a specific Bitbucket branch and found there is a possible solution within the v1 API for Bitbucket Server. While the documentation is not exactly clear on how to accomplish this, I did find a community post where someone figured out how to do this along with a StackOverflow thread on a similar topic.

The StackOverflow thread reports the following may work for your needs:


Source thread: I want to get commits on a branch in bitbucket stash via rest API

Along with this, the Community post reports the following also worked for their requirements (This is similar to your API call on getting the last commit):


Source post: Querying the last commit on a particular branch in Bitbucket using the Rest API

From my understanding on this, you should be able to use the StackOverflow response to call against the feature branch within Bitbucket and have it return commits for the said branch. Please give this a try and let us know the results.

We look forward to hearing back from you so we may find a way to link Commits to Branches within Bitbucket Server.

Stephen Sifers

Hi Stephen,

Unfortunately both solutions (which are in fact identical) produce the same outcome - the latest commit of the desired branch. Meaning that it leavens me with nothing to retrieve the other commits from the same branch.

I kind of found a partial solution by reverse engineering. Thus master branch commits always have their previous commit as a parent. Thus it is only a matter of traversing "parent->parent->parent..." until the  required depth is reached. All these "parent" items are the commits of the master branch.

But this only works because in my case we have a strict policy of not committing to master directly and only merging feature branches instead.

Meaning that this problem cannot be solved reliably. Unfortunately.

Thank you Stephen anyway.

Like constantinosm likes this

Did you ever find a solution to this? I am facing a similar problem

Nope :o(

I am afraid this can only be achieved with the new/latest API but not with the legacy version.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events