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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

REST API: Getting the branch name with the commits


Hi, is there any way to also get the branch name of the branch the commits were made on by calling the endpoint from the REST API:{workspace}/{repo-slug}/commits?


Thank you!

1 answer

1 accepted

1 vote
Answer accepted

Hello @Darius Bogdan,

This is not possible with Git, as in there's no way to do this by design. A branch in Git is just a pointer to a commit – a tip of that branch. When you create more commits on that branch, the pointer is moved to the new tip commit. However, it is possible to create commits updating any branches at all.

You can't tell which branch the commit was created at, even if there's a branch pointing to it: you can create a branch on any commit in your repository, after that commit was created. You also can remove any branch at any time, and there will be no traces of it (except for reflog which will "remember" that branch for some time), while the commits might still be reachable from other refs which will prevent them from being removed by garbage collector.

This is one of the significant differences between Git and Mercurial. The latter embeds the branch into commit metadata, so a commit always belongs to a branch. In Git, however, you can only answer a question "which branch has the specified commit", which means that commit is reachable from the tip of the branch if you follow links to commit's parents.

Does this make sense? Let me know if you have any questions.


Yes, this makes sense. Thank you for the quick response.




Like Daniil Penkin likes this

Suggest an answer

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

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,925 views 10 16
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