mohit sehrawat
mohit sehrawat

Reputation: 211

Get commits from a specific branch in github

Want to get the commits from a different branch rather than the master branch. It lists the commits from the master branch.I have 2 branch in my Repo master and test, i want the commit from the test branch instead of master.

I have already tried the below to get the list from the github repo but it gives the commits for master branch

github_commits = repo.get_commits()

full code that i have tried:

from github import Github  

g = Github(base_url="https://my_hostnaame/api/v3", 
login_or_token="my_access_token") 
org = g.get_organization("my_org") 
repo = org.get_repo("my_repo_name") 
github_commits = repo.get_commits()
print(github_commits)

Upvotes: 0

Views: 1157

Answers (1)

LinPy
LinPy

Reputation: 18578

you need to do the following:

branch = g.get_repo("my_repo_name").get_branch("master")
print(branch.commit)

I assumed you installed PyGithub

here is the full usage of branch method

Upvotes: 1

Related Questions