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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 Edited

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

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

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,926 views 0 7
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