使用PyGithub在远程上重命名git分支名称

时间:2019-02-22 10:14:48

标签: python-3.x pygithub

如何使用PyGithub python API重命名 github 远程分支?

1 个答案:

答案 0 :(得分:0)

PyGithub官方提供的参考-$replaceRoot https://github.com/PyGithub/PyGithub

from github import Github

# using username and password
g = Github("user", "password")

# or using an access token
g = Github("access_token")

# Git reference of the branch that you wish to delete
src = g.get_git_ref("heads/source branch name")

# Create new branch from old branch
g.create_git_ref("refs/heads/new branch name", sha=src.object.sha)

# Delete old branch reference
src.delete()