PyGithub - How to get a list of all commits for a particular branch?

I need to check all commits made to a particular branch on github.

I am aware of

repo.get_commits() 

but this returns commits for all branches of that repository I guess. I haven't found any branch attribute neither in Commit class nor in Gitcommit class.

Also there is not sth like .get_commits() in Branch class

What is the proper way to solve this problem?

Answers

As discussed here, this should utimately use the GitHub API List Commits

get /repos/{owner}/{repo}/commits

With as parameter the sha or branch name from which you want to list commits.

Ib PyGitHub, that is github.Repository.Repository.get_commits(), with sha – string being the name of the branch.

That will return a github.PaginatedList.PaginatedList of github.Commit.Commit

Posted on by VonC