PyGithub: How to create a branch off the master and check out?


How can I create a new branch off the master and check out the branch?

The documentation at does not show how to do this.

Thanks a lot!!

Asked By: Kay



I was able to do this with this code

g = Github("user", "pass")
repoName = "apiTest"
source_branch = 'master'
target_branch = 'newfeature'

repo = g.get_user().get_repo(repoName)
sb = repo.get_branch(source_branch)
repo.create_git_ref(ref='refs/heads/' + target_branch, sha=sb.commit.sha)
Answered By: Kay
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.