REST API: Getting the branch name with the commits

Darius Bogdan February 24, 2020

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: https://api.bitbucket.org/2.0/repositories/{workspace}/{repo-slug}/commits?

 

Thank you!

1 answer

1 accepted

1 vote
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 24, 2020

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.

Cheers,
Daniil

Darius Bogdan February 24, 2020

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

 

Regards.

Darius

Like Daniil Penkin likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events