How to get all commits in a repository along with the corresponding branch name?

Hi ! I am faced with a problem of getting all commits in a repository with the branch name too along with the commit ID . While there exists one endpoint that lists all the commits ({workspace}/{repo_slug}/commits) what this API does not give is the branch name along with the commit ID . If I call the branches endpoint : /2.0/repositories/{workspace}/{repo_slug}/refs/branches/{name} I can get only the latest commit and not all commits in the branch . To do any kind of mapping I would need to call each branch and then another loop to call each commit within a branch this causes the code to fail as I exceed the no. of requests allowed . I need some solutions to tackle this problem .

Hi @AliHussaini - just spent some time digging around, thinking I might strike some gold with the fields query string based on the full/partial representation section in the docs. But that didn’t lead anywhere.

Consider filing a feature request / suggestion ticket here:

p.s. I’m also reaching out to some folks on the Bitbucket Cloud team to see if they have any ideas.

1 Like

Hi @nmansilla Thanks for your reply ! Really appreciate it , I would like to know more about this fields query string does it mean to query the API with some parameters ?

I have been checking with the endpoints separately too (the branches endpoint and the commits endpoint ) The goal being to query only the branches which are until a certain date like for example getting all the branches active (active implies people are still committing to this branch ) say from August 2020 only 30 branches were the most active one and only for those branches I call the commits end point and get all the commits from them (until a date say august again) while I can call commits based on last modified I am unclear on how to call commits based on the date directly from the api .
Can you please see if there is some possibility in this solution where we find out the most active branches and only call commits for them ?

Are you able to “git clone --mirror” ahead of time? If yes, then try this (after cloning):

git for-each-ref --sort='-*committerdate' refs/heads