How to get branch name from commit id using azure Devops REST API

Khare, Deepalee 1 Reputation point
2021-07-25T17:52:04.42+00:00

Scenario: I need to get when was the latest commit done in the repo and by whom, and to which branch did that user do the commit on?

Solution:
I'm using python azure.devops module. and here is my code:

cm_search_criteria = models.GitQueryCommitsCriteria(history_mode='firstParent', top=10, include_links=True, include_push_data=True, include_user_image_url=True, include_work_items=True)
commits = git_client.get_commits(repo.id, search_criteria=cm_search_criteria, project=project.name)
for i in commits:
datetimeobj = datetime.strptime(i.committer.date.strftime("%x"), '%m/%d/%y')
last_commit_on = datetimeobj.date()
last_commit_by = i.committer.email
break

Now how do I get the branch name to which the user had committed the code? In the UI we can see the branch name... how can i get the same data using Azure Devops REST API ?

117685-image.png

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,192 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,451 Reputation points
    2021-07-26T03:40:44.18+00:00

    Hi @Khare, Deepalee

    Welcome to Microsoft Q&A! Thanks for posting the question.

    DevOps is currently not supported in the Q&A forums, the supported products are listed over here https://learn.microsoft.com/en-us/answers/products (more to be added later on).

    You can ask the experts in the dedicated forum over here: https://stackoverflow.com/questions/tagged/devops
    https://developercommunity.visualstudio.com/spaces/21/index.html

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.